提交 19553f73 编写于 作者: Y yinjiaming

fix: 修复测试用例中部分测试内容硬编码的问题

【背景】
A核测试用例中有一些敏感字符串需要修改

【修改方案】
将敏感的字符串改为随机生成

【影响】
对现有的产品编译不会有影响。

re #I5ALBS
Signed-off-by: Nyinjiaming <yinjiaming@huawei.com>
Change-Id: Ib9b023ace6be1d58248c993f7b9919a96afbea96
上级 fa6b2d35
......@@ -32,18 +32,36 @@
#include <libintl.h>
#include <locale.h>
const int domain_name_length = 10;
const int buffer_size = 50;
static UINT32 testcase(VOID)
{
char *s = "";
char domain[buffer_size], tmp[domain_name_length];
srand(time(NULL));
for (int i = 0, r = 0; i < domain_name_length; i++) {
r = rand() % 36; // 36: 0-9 and a-z
if (r < 10) { // 10: 0-9
tmp[i] = '0' + r;
} else {
tmp[i] = 'a' + r;
}
}
int ret = sprintf_s(domain, sizeof(domain), "www.%s.com", tmp);
if (ret == 0) {
printf("sprinf_s failed\n");
return LOS_NOK;
}
setlocale(LC_ALL, "");
textdomain("gettext_demo");
bindtextdomain("gettext_demo", ".");
bind_textdomain_codeset("gettext_demo", "UTF-8");
printf(dcgettext("www.huawei.com", "TestString1\n", LC_MESSAGES));
printf(dcgettext(domain, "TestString1\n", LC_MESSAGES));
s = dcgettext("www.huawei.com", "TestString1\n", LC_MESSAGES);
s = dcgettext(domain, "TestString1\n", LC_MESSAGES);
printf("[INFO]%s:%d,%s,s=%s\n", __FILE__, __LINE__, __func__, s);
ICUNIT_ASSERT_STRING_EQUAL(s, "TestString1\n", s);
setlocale(LC_ALL, "C");
......
......@@ -30,7 +30,7 @@
*/
#include "It_test_sys.h"
#define TEST_PASSWORD (char *)"test1234"
const int password_length = 10;
static UINT32 TestCase(VOID)
{
......@@ -39,14 +39,24 @@ static UINT32 TestCase(VOID)
char *key = NULL;
char slat[2];
int ret;
char test_password[password_length];
srand(time(NULL));
for (int i = 0, r = 0; i < password_length; i++) {
r = rand() % 36; // 36: 0-9 and a-z
if (r < 10) { // 10: 0-9
test_password[i] = '0' + r;
} else {
test_password[i] = 'a' + r;
}
}
key = TEST_PASSWORD;
key = test_password;
slat[0] = key[0];
slat[1] = key[1];
passwd1 = crypt(key, slat);
ICUNIT_GOTO_NOT_EQUAL(passwd1, NULL, passwd1, EXIT);
key = TEST_PASSWORD;
key = test_password;
slat[0] = passwd1[0];
slat[1] = passwd1[1];
passwd2 = crypt(key, slat);
......
......@@ -32,21 +32,31 @@
#include <lt_net_resolv.h>
const int buffer_size = 20;
static int EtherAtonTest(void)
{
struct ether_addr *eaddr = ether_aton("01::EF");
ICUNIT_ASSERT_EQUAL(eaddr, NULL, -1);
eaddr = ether_aton("2C:9D:1E:4A:41:55");
char mac_addr[buffer_size], *tmp = mac_addr;
int r[ETH_ALEN];
srand(time(NULL));
for (int i = 0; i < ETH_ALEN; i++) {
r[i] = rand() % 0xff;
}
// 0, 1, 2, 3, 4, 5: 6 elements of mac address.
(void)sprintf_s(mac_addr, sizeof(mac_addr), "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", r[0], r[1], r[2], r[3], r[4], r[5]);
eaddr = ether_aton(mac_addr);
ICUNIT_ASSERT_NOT_EQUAL(eaddr, NULL, -1);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[0], 0x2C, eaddr->ether_addr_octet[0]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[1], 0x9D, eaddr->ether_addr_octet[1]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[2], 0x1E, eaddr->ether_addr_octet[2]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[3], 0x4A, eaddr->ether_addr_octet[3]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[4], 0x41, eaddr->ether_addr_octet[4]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[5], 0x55, eaddr->ether_addr_octet[5]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[0], r[0], eaddr->ether_addr_octet[0]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[1], r[1], eaddr->ether_addr_octet[1]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[2], r[2], eaddr->ether_addr_octet[2]); // 2: compare r[2] with eaddr
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[3], r[3], eaddr->ether_addr_octet[3]); // 3: compare r[3] with eaddr
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[4], r[4], eaddr->ether_addr_octet[4]); // 4: compare r[4] with eaddr
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[5], r[5], eaddr->ether_addr_octet[5]); // 5: compare r[5] with eaddr
return ICUNIT_SUCCESS;
}
......
......@@ -32,6 +32,8 @@
#include <lt_net_resolv.h>
const int buffer_size = 20;
static int EtherAtonrTest(void)
{
struct ether_addr addr;
......@@ -39,15 +41,23 @@ static int EtherAtonrTest(void)
ICUNIT_ASSERT_EQUAL(eaddr, NULL, -1);
eaddr = ether_aton_r("2c:9d:1e:4A:41:55", &addr);
char mac_addr[buffer_size], *tmp = mac_addr;
int r[ETH_ALEN];
srand(time(NULL));
for (int i = 0; i < ETH_ALEN; i++) {
r[i] = rand() % 0xff;
}
// 0, 1, 2, 3, 4, 5: 6 elements of mac address.
(void)sprintf_s(mac_addr, sizeof(mac_addr), "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", r[0], r[1], r[2], r[3], r[4], r[5]);
eaddr = ether_aton_r(mac_addr, &addr);
ICUNIT_ASSERT_EQUAL(eaddr, &addr, -1);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[0], 0x2c, eaddr->ether_addr_octet[0]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[1], 0x9d, eaddr->ether_addr_octet[1]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[2], 0x1e, eaddr->ether_addr_octet[2]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[3], 0x4a, eaddr->ether_addr_octet[3]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[4], 0x41, eaddr->ether_addr_octet[4]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[5], 0x55, eaddr->ether_addr_octet[5]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[0], r[0], eaddr->ether_addr_octet[0]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[1], r[1], eaddr->ether_addr_octet[1]);
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[2], r[2], eaddr->ether_addr_octet[2]); // 2: compare r[2] with eaddr
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[3], r[3], eaddr->ether_addr_octet[3]); // 3: compare r[3] with eaddr
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[4], r[4], eaddr->ether_addr_octet[4]); // 4: compare r[4] with eaddr
ICUNIT_ASSERT_EQUAL(eaddr->ether_addr_octet[5], r[5], eaddr->ether_addr_octet[5]); // 5: compare r[5] with eaddr
return ICUNIT_SUCCESS;
}
......
......@@ -32,13 +32,26 @@
#include <lt_net_resolv.h>
const int buffer_size = 20;
static int EtherNtoaTest(void)
{
struct ether_addr addr = {{11,12,13,14,15,16}}, *eaddr = &addr;
struct ether_addr addr, *eaddr = &addr;
srand(time(NULL));
int r[ETH_ALEN];
for (int i = 0; i < ETH_ALEN; i++) {
r[i] = rand() % 16; // 16: 0x0-0xf
eaddr->ether_addr_octet[i] = r[i];
}
char *buf = ether_ntoa(eaddr);
char str1[buffer_size], str2[buffer_size];
// 0, 1, 2, 3, 4, 5: 6 elements of mac address.
(void)sprintf_s(str1, sizeof(str1), "%x:%x:%x:%x:%x:%x", r[0], r[1], r[2], r[3], r[4], r[5]);
// 0, 1, 2, 3, 4, 5: 6 elements of mac address.
(void)sprintf_s(str2, sizeof(str2), "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", r[0], r[1], r[2], r[3], r[4], r[5]);
ICUNIT_ASSERT_NOT_EQUAL(buf, 0, -1);
ICUNIT_ASSERT_EQUAL((stricmp("b:c:d:e:f:10", buf) == 0 || stricmp("0b:0c:0d:0e:0f:10", buf) == 0), 1, printf("%s\n", buf));
ICUNIT_ASSERT_EQUAL((stricmp(str1, buf) == 0 || stricmp(str2, buf) == 0), 1, printf("%s\n", buf));
return ICUNIT_SUCCESS;
}
......
......@@ -31,13 +31,27 @@
#include <lt_net_resolv.h>
const int buffer_size = 20;
static int EtherNtoarTest(void)
{
struct ether_addr addr = {{11,12,13,4,15,16}}, *eaddr = &addr;
struct ether_addr addr, *eaddr = &addr;
srand(time(NULL));
int r[ETH_ALEN];
for (int i = 0; i < ETH_ALEN; i++) {
r[i] = rand() % 16; // 16: 0x0-0xf
eaddr->ether_addr_octet[i] = r[i];
}
char buf[100], *p = ether_ntoa_r(eaddr, buf);
char str1[buffer_size], str2[buffer_size];
// 0, 1, 2, 3, 4, 5: 6 elements of mac address.
(void)sprintf_s(str1, sizeof(str1), "%x:%x:%x:%x:%x:%x", r[0], r[1], r[2], r[3], r[4], r[5]);
// 0, 1, 2, 3, 4, 5: 6 elements of mac address.
(void)sprintf_s(str2, sizeof(str2), "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", r[0], r[1], r[2], r[3], r[4], r[5]);
ICUNIT_ASSERT_EQUAL(p, buf, (intptr_t)p);
ICUNIT_ASSERT_EQUAL((stricmp("b:c:d:4:f:10", buf) == 0 || stricmp("0b:0c:0d:04:0f:10", buf) == 0), 1, printf("%s\n", p));
ICUNIT_ASSERT_EQUAL((stricmp(str1, buf) == 0 || stricmp(str2, buf) == 0), 1, printf("%s\n", p));
return ICUNIT_SUCCESS;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册