1 Star 0 Fork 24

Apricity/dhcp

forked from src-openEuler/dhcp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
add-a-test-case-to-parse-code93-in-option_unittest.patch 3.32 KB
一键复制 编辑 原始数据 按行查看 历史
From bd6db12aaeecbc4f76462b4016c7e74e43d532f3 Mon Sep 17 00:00:00 2001
From: zhangqiumiao <zhangqiumiao1@huawei.com>
Date: Tue, 10 Nov 2020 02:10:57 -0500
Subject: [PATCH] add a test case to parse code93 in option_unittest
---
common/tests/option_unittest.c | 70 ++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/common/tests/option_unittest.c b/common/tests/option_unittest.c
index cd52cfb..0bb6517 100644
--- a/common/tests/option_unittest.c
+++ b/common/tests/option_unittest.c
@@ -129,6 +129,75 @@ ATF_TC_BODY(pretty_print_option, tc)
}
}
+ATF_TC(parse_code93_option);
+
+ATF_TC_HEAD(parse_code93_option, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Verify that code93 can be parsed.");
+}
+
+ATF_TC_BODY(parse_code93_option, tc)
+{
+ struct option *option;
+ unsigned code;
+ unsigned char bad_data[32*1024];
+ unsigned char good_data1[] = { 0,0 };
+ unsigned char good_data2[] = { 0,7 };
+ unsigned char good_data3[] = { 0,11 };
+ int emit_commas = 1;
+ int emit_quotes = 1;
+ const char *output_buf;
+
+ /* Initialize whole thing to non-printable chars */
+ memset(bad_data, 0x1f, sizeof(bad_data));
+
+ initialize_common_option_spaces();
+
+ /* We'll use pxe-system-type and it happens to be format Sa */
+ code = 93;
+ option = NULL;
+ if (!option_code_hash_lookup(&option, dhcp_universe.code_hash,
+ &code, 0, MDL)) {
+ atf_tc_fail("can't find option %d", code);
+ }
+
+ if (option == NULL) {
+ atf_tc_fail("option is NULL");
+ }
+
+ /* First we will try a good value we know should fit. */
+ output_buf = pretty_print_option (option, good_data1, sizeof(good_data1),
+ emit_commas, emit_quotes);
+
+ /* Make sure we get what we expect */
+ if (!output_buf || strcmp(output_buf, "0")) {
+ atf_tc_fail("pretty_print_option 1 did not return \"<error>\"");
+ }
+
+ output_buf = pretty_print_option (option, good_data2, sizeof(good_data3),
+ emit_commas, emit_quotes);
+ /* Make sure we get what we expect */
+ if (!output_buf || strcmp(output_buf, "7")) {
+ atf_tc_fail("pretty_print_option 2 did not return \"<error>\"");
+ }
+
+ output_buf = pretty_print_option (option, good_data3, sizeof(good_data3),
+ emit_commas, emit_quotes);
+ /* Make sure we get what we expect */
+ if (!output_buf || strcmp(output_buf, "11")) {
+ atf_tc_fail("pretty_print_option 3 did not return \"<error>\"");
+ }
+
+ /* Now we'll try a data value that's too large */
+ output_buf = pretty_print_option (option, bad_data, sizeof(bad_data),
+ emit_commas, emit_quotes);
+
+ /* Make sure we safely get an error */
+ if (!output_buf || strcmp(output_buf, "<error>")) {
+ atf_tc_fail("pretty_print_option did not return \"<error>\"");
+ }
+}
/* This macro defines main() method that will call specified
test cases. tp and simple_test_case names can be whatever you want
@@ -137,6 +206,7 @@ ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, option_refcnt);
ATF_TP_ADD_TC(tp, pretty_print_option);
+ ATF_TP_ADD_TC(tp, parse_code93_option);
return (atf_no_error());
}
--
2.19.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zengwefeng/dhcp.git
git@gitee.com:zengwefeng/dhcp.git
zengwefeng
dhcp
dhcp
master

搜索帮助