提交 7130363e 编写于 作者: R Robert Drab

Fix potential segfaults in test cases

In many places checking for nullptr is done using EXPECT test macros
that doesn't return from the function when condition is not met
(i.e. they are non-fatal). Lack of further error handling results
in a subsequent segfault. To avoid that in most places it's sufficient
to change macro type to ASSERT.
Signed-off-by: NRobert Drab <robert.drab@huawei.com>
上级 4f70d1b7
......@@ -932,14 +932,11 @@ HWTEST_F(ActsLwipTest, testInetNtopIpv4Normal, Function | MediumTest | Level2)
inputAddr.s_addr = inputBig[i];
#endif
ret = inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff));
if (ret == nullptr) {
EXPECT_TRUE(ret != nullptr) << "ErrInfo:inet_ntop NULL [" << expectAddrs[i] << "]";
} else {
ASSERT_NE(ret, nullptr) << "ErrInfo:inet_ntop NULL [" << expectAddrs[i] << "]";
printf("inet_ntop expect [%s]: ret[%s], buf[%s]\n", expectAddrs[i], ret, rstBuff);
EXPECT_STREQ(expectAddrs[i], ret);
EXPECT_STREQ(expectAddrs[i], rstBuff);
}
}
}
/**
......
......@@ -78,7 +78,7 @@ HWTEST_P(DateTimeTest, GLOBAL_DateTimeFormat_Format_0100, Function | MediumTest
int length = sizeof(patternFormats) / sizeof(patternFormats[0]);
for (int i = 0; i < length; i++) {
DateTimeFormat *datetime = new DateTimeFormat(patternFormats[i], localeInfo);
EXPECT_TRUE(datetime != nullptr);
ASSERT_TRUE(datetime != nullptr);
time_t cal = 3600 * 3 + 3600 * 24 * 6;
I18nStatus status = I18nStatus::ISUCCESS;
string appendTo = "";
......@@ -108,7 +108,7 @@ HWTEST_P(DateTimeTest, GLOBAL_DateTimeFormat_Format_0200, Function | MediumTest
int length = sizeof(patternFormats) / sizeof(patternFormats[0]);
for (int i = 0; i < length; i++) {
DateTimeFormat *datetime = new DateTimeFormat(patternFormats[i], localeInfo);
EXPECT_TRUE(datetime != nullptr);
ASSERT_TRUE(datetime != nullptr);
time_t cal = 3600 * 3 + 3600 * 24 * 6;
I18nStatus status = I18nStatus::ISUCCESS;
string appendTo = "";
......@@ -138,7 +138,7 @@ HWTEST_P(DateTimeTest, GLOBAL_DateTimeFormat_Format_0300, Function | MediumTest
int length = sizeof(patternFormats) / sizeof(patternFormats[0]);
for (int i = 0; i < length; i++) {
DateTimeFormat *datetime = new DateTimeFormat(patternFormats[i], localeInfo);
EXPECT_TRUE(datetime != nullptr);
ASSERT_TRUE(datetime != nullptr);
time_t cal = 3600 * 3 + 3600 * 24 * 6;
I18nStatus status = I18nStatus::ISUCCESS;
string appendTo = "";
......
......@@ -48,7 +48,7 @@ HWTEST_F(FileSystemTest, testReaddir, Function | MediumTest | Level3)
CreateTestFolder();
dirp = opendir(TOP_DIR "/" DIR0);
EXPECT_NE(dirp, nullptr) << "> opendir errno = " << errno;
ASSERT_NE(dirp, nullptr) << "> opendir errno = " << errno;
for (int i = 0; i < 10; i++) { // Prevents infinite loops.
dResult = readdir(dirp);
if (dResult == nullptr) {
......@@ -83,7 +83,7 @@ HWTEST_F(FileSystemTest, testReaddirEbadf, Function | MediumTest | Level3)
CreateTestFolder();
dirp = opendir(TOP_DIR "/" DIR0);
EXPECT_NE(dirp, nullptr) << "> opendir errno = " << errno;
ASSERT_NE(dirp, nullptr) << "> opendir errno = " << errno;
EXPECT_EQ(closedir(dirp), 0) << "> closedir errno = " << errno;
dResult = readdir(dirp);
......@@ -106,7 +106,7 @@ HWTEST_F(FileSystemTest, testReaddirR, Function | MediumTest | Level3)
CreateTestFolder();
dirp = opendir(TOP_DIR "/" DIR0);
EXPECT_NE(dirp, nullptr) << "> opendir errno = " << errno;
ASSERT_NE(dirp, nullptr) << "> opendir errno = " << errno;
for (int i = 0; i < 10; i++) { // Prevents infinite loops.
if ((readdir_r(dirp, &dEntry, &dResult)) != 0) {
break;
......@@ -174,24 +174,24 @@ HWTEST_F(FileSystemTest, testSeekdir, Function | MediumTest | Level3)
CreateTestFolder();
dirp = opendir(TOP_DIR "/" DIR0);
EXPECT_NE(dirp, nullptr) << "> opendir errno = " << errno;
ASSERT_NE(dirp, nullptr) << "> opendir errno = " << errno;
dResult = readdir(dirp);
EXPECT_FALSE(dResult == nullptr) << "> readdir errno = " << errno;
ASSERT_FALSE(dResult == nullptr) << "> readdir errno = " << errno;
EXPECT_EQ(telldir(dirp), dResult->d_off);
LOG("> dResult->d_name = %s", dResult->d_name);
LOG("> dResult->d_off = %lu", dResult->d_off);
long tellDir0 = dResult->d_off;
dResult = readdir(dirp);
EXPECT_FALSE(dResult == nullptr) << "> readdir errno = " << errno;
ASSERT_FALSE(dResult == nullptr) << "> readdir errno = " << errno;
EXPECT_EQ(telldir(dirp), dResult->d_off);
LOG("> dResult->d_name = %s", dResult->d_name);
LOG("> dResult->d_off = %lu", dResult->d_off);
long tellDir1 = dResult->d_off;
dResult = readdir(dirp);
EXPECT_FALSE(dResult == nullptr) << "> readdir errno = " << errno;
ASSERT_FALSE(dResult == nullptr) << "> readdir errno = " << errno;
LOG("> 111");
EXPECT_EQ(telldir(dirp), dResult->d_off);
LOG("> 222");
......@@ -201,7 +201,7 @@ HWTEST_F(FileSystemTest, testSeekdir, Function | MediumTest | Level3)
rewinddir(dirp);
dResult = readdir(dirp);
EXPECT_FALSE(dResult == nullptr) << "> readdir errno = " << errno;
ASSERT_FALSE(dResult == nullptr) << "> readdir errno = " << errno;
EXPECT_EQ(telldir(dirp), dResult->d_off);
EXPECT_EQ(telldir(dirp), tellDir0);
LOG("> dResult->d_name = %s", dResult->d_name);
......@@ -209,7 +209,7 @@ HWTEST_F(FileSystemTest, testSeekdir, Function | MediumTest | Level3)
seekdir(dirp, tellDir1);
dResult = readdir(dirp);
EXPECT_FALSE(dResult == nullptr) << "> readdir errno = " << errno;
ASSERT_FALSE(dResult == nullptr) << "> readdir errno = " << errno;
EXPECT_EQ(telldir(dirp), dResult->d_off);
EXPECT_EQ(telldir(dirp), tellDir2);
LOG("> dResult->d_name = %s", dResult->d_name);
......@@ -231,7 +231,7 @@ HWTEST_F(FileSystemTest, testOpendir, Function | MediumTest | Level2)
errno = 0;
dirp = opendir(TOP_DIR "/" DIR0);
EXPECT_NE(dirp, nullptr);
ASSERT_NE(dirp, nullptr);
EXPECT_EQ(errno, 0);
EXPECT_EQ(closedir(dirp), 0) << "> closedir errno = " << errno;
}
......@@ -326,6 +326,6 @@ HWTEST_F(FileSystemTest, testClosedir, Function | MediumTest | Level3)
CreateTestFolder();
dirp = opendir(TOP_DIR "/" DIR0);
EXPECT_NE(dirp, nullptr) << "> opendir errno = " << errno;
ASSERT_NE(dirp, nullptr) << "> opendir errno = " << errno;
EXPECT_EQ(closedir(dirp), 0) << "> closedir errno = " << errno;
}
......@@ -53,7 +53,7 @@ HWTEST_F(FileSystemTest, testPath, Function | MediumTest | Level1)
// get dir
char *workDir = dirname((char*)FILE0);
EXPECT_NE(workDir, nullptr) << "> dirname errno = " << errno;
ASSERT_NE(workDir, nullptr) << "> dirname errno = " << errno;
EXPECT_STREQ(".", workDir);
LOG("> workDir = %s", workDir);
}
......@@ -73,7 +73,7 @@ HWTEST_F(FileSystemTest, testGetCurrentDirName, Function | MediumTest | Level1)
// get current dir name
const char *currentDirStandard = TOP_DIR;
char *currentDir = get_current_dir_name();
EXPECT_NE(currentDir, nullptr);
ASSERT_NE(currentDir, nullptr);
EXPECT_STREQ(currentDir, currentDirStandard);
LOG("> currentDir = %s", currentDir);
}
......@@ -92,7 +92,7 @@ HWTEST_F(FileSystemTest, testBasename, Function | MediumTest | Level1)
// get file name
char *desName = basename((char*)FILE0);
EXPECT_NE(desName, nullptr) << "> basename errno = " << errno;
ASSERT_NE(desName, nullptr) << "> basename errno = " << errno;
EXPECT_STREQ(desName, FILE0);
LOG("> desName = %s", desName);
}
......@@ -271,7 +271,7 @@ HWTEST_F(FileSystemTest, testFwprintf, Function | MediumTest | Level3)
// read
fp = fopen(filePath, "r");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
EXPECT_NE(fgetws(readBuf, 30, fp), nullptr) << "fgetws error";
EXPECT_TRUE(wcscmp(writeBuf, readBuf) == 0) << "writeBuf != readBuf";
EXPECT_NE(fclose(fp), -1) << "> fclose errno =" << errno;
......
......@@ -51,13 +51,13 @@ HWTEST_F(FileSystemTest, testFILE, Function | MediumTest | Level2)
EXPECT_NE(fd, -1) << "> creat faild errno = " << errno;
EXPECT_NE(close(fd), -1) << "> close errno = " << errno;
fp = fopen(FILE0, "w+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
EXPECT_EQ(fwrite(writeBuf, sizeof(writeBuf), 1, fp), 1) << "> fwrite errno = " << errno;
EXPECT_NE(fclose(fp), -1) << "> fclose errno =" << errno;
// read
fp = fopen(FILE0, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
EXPECT_NE(fread(readBuf, sizeof(writeBuf), 1, fp), 0) << "> fread errno = " << errno;
EXPECT_STREQ(writeBuf, readBuf) << "> writeBuf = " << writeBuf << "\n> readBuf = " << readBuf;
EXPECT_NE(fclose(fp), -1) << "> fclose errno =" << errno;
......@@ -82,7 +82,7 @@ HWTEST_F(FileSystemTest, testFeof, Function | MediumTest | Level3)
// read
fp = fopen(FILE0, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
EXPECT_EQ(fseeko(fp, 0, SEEK_SET), 0) << "> fseeko errno = " << errno;
fgetc(fp);
......@@ -115,7 +115,7 @@ HWTEST_F(FileSystemTest, testFseek, Function | MediumTest | Level3)
// read
fp = fopen(FILE0, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
fpos_t offset;
EXPECT_EQ(fgetpos(fp, &offset), 0) << "> fgetpos errno = " << errno;
......@@ -148,7 +148,7 @@ HWTEST_F(FileSystemTest, testFseekSeekCur, Function | MediumTest | Level3)
// read
fp = fopen(FILE0, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
fpos_t offset;
EXPECT_EQ(fgetpos(fp, &offset), 0) << "> fgetpos errno = " << errno;
......@@ -181,7 +181,7 @@ HWTEST_F(FileSystemTest, testFseekSeekEnd, Function | MediumTest | Level3)
// read
fp = fopen(FILE0, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
fpos_t offset;
EXPECT_EQ(fgetpos(fp, &offset), 0) << "> fgetpos errno = " << errno;
......@@ -214,7 +214,7 @@ HWTEST_F(FileSystemTest, testFseeko, Function | MediumTest | Level3)
// read
fp = fopen(FILE0, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
EXPECT_EQ(fseeko(fp, 2, SEEK_SET), 0) << "> fseeko errno = " << errno;
EXPECT_EQ(ftello(fp), 2) << " errno = " << errno;
......@@ -245,7 +245,7 @@ HWTEST_F(FileSystemTest, testFseekoSeekCur, Function | MediumTest | Level3)
// read
fp = fopen(FILE0, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
EXPECT_EQ(fseeko(fp, 2, SEEK_CUR), 0) << "> fseeko errno = " << errno;
EXPECT_EQ(ftello(fp), 2) << " errno = " << errno;
......@@ -276,7 +276,7 @@ HWTEST_F(FileSystemTest, testFseekoSeekEnd, Function | MediumTest | Level3)
// read
fp = fopen(FILE0, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
EXPECT_EQ(fseeko(fp, 0, SEEK_END), 0) << "> fseeko errno = " << errno;
EXPECT_EQ(ftello(fp), sizeof(writeBuf)) << " errno = " << errno;
......@@ -315,7 +315,7 @@ HWTEST_F(FileSystemTest, testFunlockfile, Function | MediumTest | Level3)
CreateTestFolder();
FILE *fp = fopen(filePath, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
pthread_t tid;
int reInt = pthread_create(&tid, nullptr, ChildWrite, (void*)fp);
......@@ -351,7 +351,7 @@ HWTEST_F(FileSystemTest, testFileno, Function | MediumTest | Level2)
ASSERT_NE(close(fd), -1) << "> close errno = " << errno;
fp = fopen(filePath, "w+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
fd = fileno(fp);
EXPECT_NE(fd, -1) << "> fileno errno = " << errno;
WriteCloseTest(fd);
......@@ -380,7 +380,7 @@ HWTEST_F(FileSystemTest, testFileno1, Function | MediumTest | Level2)
// read
fp = fopen(filePath, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
fd = fileno(fp);
EXPECT_NE(fd, -1) << "> fileno errno = " << errno;
......@@ -458,14 +458,14 @@ HWTEST_F(FileSystemTest, testFflush, Function | MediumTest | Level3)
}
Msleep(50);
FILE *fp = fopen(filePath, "r");
EXPECT_NE(fp, nullptr);
ASSERT_NE(fp, nullptr);
EXPECT_EQ(fseek(fp, 0, SEEK_END), 0) << "> fseek errno = " << errno;
EXPECT_EQ(ftell(fp), 0);
EXPECT_NE(fclose(fp), -1) << "> fclose errno =" << errno;
Msleep(100);
fp = fopen(filePath, "r");
EXPECT_NE(fp, nullptr);
ASSERT_NE(fp, nullptr);
EXPECT_NE(fread(readBuf, sizeof(writeBuf), 1, fp), 0) << "> fread errno = " << errno;
EXPECT_STREQ(readBuf, writeBuf);
LOG("> readBuf = %s", readBuf);
......
......@@ -120,7 +120,7 @@ HWTEST_F(FileSystemTest, testRealpath, Function | MediumTest | Level3)
// get Absolute Path
const char *realPathStandard = TOP_DIR "/" FILE0;
char *realPath = (char*)malloc(256);
EXPECT_NE(realpath(FILE0, realPath), nullptr) << "> realpath errno = " << errno;
ASSERT_NE(realpath(FILE0, realPath), nullptr) << "> realpath errno = " << errno;
EXPECT_STREQ(realPath, realPathStandard);
LOG("> realPath = %s", realPath);
free(realPath);
......
......@@ -606,7 +606,7 @@ HWTEST_F(IoTest, testPerror, Function | MediumTest | Level1)
WaitProcExitedOK(pid);
FILE *fp1 = fopen(IOTEST_TEMPFILE, "r");
EXPECT_NE(fp1, nullptr) << "fopen fail, errno = " << errno;
ASSERT_NE(fp1, nullptr) << "fopen fail, errno = " << errno;
char str[100] = {0};
char *gStr = fgets(str, sizeof(str), fp1);
EXPECT_STREQ(gStr, str);
......@@ -737,15 +737,19 @@ void *Thread(void *arg)
{
FILE *fp = fopen(IOTEST_TEMPFILE, "w");
EXPECT_NE(fp, nullptr) << "fopen fail, errno = " << errno;
if (fp) {
EXPECT_NE(fputs("hello world", fp), -1) << "fputs fail, errno = " << errno;
EXPECT_NE(fclose(fp), -1) << "fclose fail, errno = " << errno;
}
FILE *fp1 = freopen(IOTEST_TEMPFILE, "r", stdin);
EXPECT_TRUE(fp1 != nullptr) << "freopen fail, errno = " << errno;
if (fp1) {
if (getchar_unlocked() != EOF) {
EXPECT_NE(getchar_unlocked(), -1) << "getchar_unlocked fail, errno = " << errno;
}
EXPECT_NE(fclose(fp1), -1) << "fclose fail, errno = " << errno;
}
return nullptr;
}
......
......@@ -132,7 +132,7 @@ HWTEST_F(MemApiTest, testReallocMem, Function | MediumTest | Level3)
memset(mem, testChar, mlen);
rlen = GetRandom(0x200000);
mem = realloc(mem, rlen);
EXPECT_TRUE(mem != nullptr) << "mem == NULL, i = " << i;
ASSERT_TRUE(mem != nullptr) << "mem == NULL, i = " << i;
len = mlen <= rlen ? mlen : rlen;
......@@ -558,7 +558,7 @@ HWTEST_F(MemApiTest, testOpenMemstreamBase, Function | MediumTest | Level2)
FILE *stream = open_memstream(&buf, &len);
ASSERT_TRUE(stream != nullptr) << "stream == nullptr";
EXPECT_TRUE(buf != nullptr && len == 0) << "buf == nullptr or len != 0";
ASSERT_TRUE(buf != nullptr && len == 0) << "buf == nullptr or len != 0";
fprintf(stream, wBuf);
fflush(stream);
......
......@@ -1367,7 +1367,7 @@ HWTEST_F(ActsNetTest, testEtherConvertNormal, Function | MediumTest | Level2)
for (int i = 0; i < 3; i++) {
atonRst = nullptr;
atonRst = ether_aton(addrHex[i]);
EXPECT_TRUE(atonRst != nullptr);
ASSERT_TRUE(atonRst != nullptr);
int ret = sprintf_s(atonByteRst, sizeof(atonByteRst), "%u.%u.%u.%u.%u.%u",
atonRst->ether_addr_octet[0], atonRst->ether_addr_octet[1],
atonRst->ether_addr_octet[2], atonRst->ether_addr_octet[3],
......@@ -1406,13 +1406,13 @@ HWTEST_F(ActsNetTest, testEtherConvertNormalWithThreadSafe, Function | MediumTes
char* ntoaPointRst = nullptr;
struct ether_addr *atonPointRst = nullptr;
struct ether_addr *atonDataRst = (ether_addr *)malloc(sizeof(ether_addr));
EXPECT_TRUE(atonDataRst != nullptr);
ASSERT_TRUE(atonDataRst != nullptr);
char addrHex[3][18] = {"FF:FF:FF:FF:FF:FF", "00:00:00:00:00:00", "5F:4E:2C:3D:1B:0A"};
char addrByte[3][24] = {"255.255.255.255.255.255", "0.0.0.0.0.0", "95.78.44.61.27.10"};
for (int i = 0; i < 3; i++) {
atonPointRst = nullptr;
atonPointRst = ether_aton_r(addrHex[i], atonDataRst);
EXPECT_TRUE(atonPointRst != nullptr);
ASSERT_TRUE(atonPointRst != nullptr);
char byteRst[24];
ret = sprintf_s(byteRst, sizeof(byteRst), "%u.%u.%u.%u.%u.%u",
atonDataRst->ether_addr_octet[0], atonDataRst->ether_addr_octet[1],
......
......@@ -85,7 +85,7 @@ HWTEST_F(ProcessTest, testLineBigExitFlush, Function | MediumTest | Level3)
// read
FILE *fp = fopen(testFile, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
EXPECT_EQ(fread(readBuf, sizeof(writeBuf), 1, fp), 0);
EXPECT_STRNE(writeBuf, readBuf) << "> writeBuf = " << writeBuf\
<< "\n> readBuf = " << readBuf;
......@@ -195,7 +195,7 @@ HWTEST_F(ProcessTest, testLineExitFlush, Function | MediumTest | Level3)
// read
FILE *fp = fopen(testFile, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
EXPECT_EQ(fread(readBuf, sizeof(writeBuf), 1, fp), 0);
EXPECT_STRNE(writeBuf, readBuf) << "> writeBuf = " << writeBuf\
<< "\n> readBuf = " << readBuf;
......@@ -305,7 +305,7 @@ HWTEST_F(ProcessTest, testExitFlush, Function | MediumTest | Level3)
// read
FILE *fp = fopen(testFile, "r+");
EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno;
ASSERT_NE(fp, nullptr) << "> fopen errno = " << errno;
EXPECT_NE(fread(readBuf, sizeof(writeBuf), 1, fp), 0);
EXPECT_STREQ(writeBuf, readBuf) << "> writeBuf = " << writeBuf\
<< "\n> readBuf = " << readBuf;
......
......@@ -550,7 +550,8 @@ void VerrxLog(const char *format, ...)
void CheckStdPrint(const char *res)
{
FILE *fp1 = fopen(SYS_TEST_FILE_01, "r");
EXPECT_FALSE(fp1 == nullptr) << "fopen fail, errno = " << errno;
ASSERT_FALSE(fp1 == nullptr) << "fopen fail, errno = " << errno;
char str[100] = {0};
char *gStr = fgets(str, sizeof(str), fp1);
printf("gStr = %s\n", gStr);
......
......@@ -373,7 +373,7 @@ HWTEST_F(ClockTimeTest, testGetdateBasic, Function | MediumTest | Level1) {
FILE *fp = nullptr;
char mask[20] = "%Y-%m-%d %H:%M:%S";
fp = fopen(DATEMSK_FILE, "w+");
EXPECT_NE(nullptr, fp);
ASSERT_NE(nullptr, fp);
int ret = fwrite(mask, sizeof(mask), 1, fp);
EXPECT_TRUE(ret > 0);
ret = setenv("DATEMSK", DATEMSK_FILE, 1);
......@@ -386,7 +386,7 @@ HWTEST_F(ClockTimeTest, testGetdateBasic, Function | MediumTest | Level1) {
struct tm *retTm = nullptr;
const char *cInput = "2020-10-26 00:01:01";
retTm = getdate(cInput);
EXPECT_NE(nullptr, retTm) << " getdate fail errno:" << getdate_err;
ASSERT_NE(nullptr, retTm) << " getdate fail errno:" << getdate_err;
strftime(cTime, sizeof(cTime), mask, retTm);
EXPECT_STREQ(cInput, cTime);
strftime(cTime, sizeof(cTime), "%D %A %H:%M:%S", retTm);
......@@ -423,7 +423,7 @@ HWTEST_F(ClockTimeTest, testGetdateError, Function | MediumTest | Level2) {
FILE *fp = nullptr;
char mask[10] = "%H:%M:%S";
fp = fopen(DATEMSK_FILE, "w+");
EXPECT_NE(nullptr, fp);
ASSERT_NE(nullptr, fp);
ret = fwrite(mask, sizeof(mask), 1, fp);
EXPECT_TRUE(ret > 0);
ret = fclose(fp);
......
......@@ -175,19 +175,23 @@ HWTEST_F(TimeUtilsTest, testGmtime, Function | MediumTest | Level3)
{
time_t time1 = 18880;
struct tm *stm = gmtime(&time1);
ASSERT_NE(nullptr, stm);
EXPECT_EQ(stm->tm_hour, 05) << "gmtime return error!";
EXPECT_STREQ(asctime(stm), "Thu Jan 1 05:14:40 1970\n") << "gmtime return error!";
time1 = LONG_MAX;
stm = gmtime(&time1);
ASSERT_NE(nullptr, stm);
EXPECT_STREQ(asctime(stm), "Tue Jan 19 03:14:07 2038\n") << "gmtime return error!";
time1 = 253402300799;
stm = gmtime(&time1);
ASSERT_NE(nullptr, stm);
EXPECT_STREQ(asctime(stm), "Fri Dec 31 23:59:59 9999\n") << "gmtime return error!";
time1 = LONG_MIN;
stm = gmtime(&time1);
ASSERT_NE(nullptr, stm);
EXPECT_STREQ(asctime(stm), "Fri Dec 13 20:45:52 1901\n") << "gmtime return error!";
}
......@@ -200,6 +204,7 @@ HWTEST_F(TimeUtilsTest, testGmtimeR, Function | MediumTest | Level3)
{
struct tm res = {0};
struct tm *stm = gmtime_r(&g_time, &res);
ASSERT_NE(nullptr, stm);
EXPECT_EQ(stm->tm_hour, 05) << "gmtime_r return error!";
EXPECT_STREQ(asctime(stm), "Thu Jan 1 05:14:40 1970\n") << "gmtime_r return error!";
EXPECT_TRUE(stm == &res) << "gmtime_r returns not equal";
......@@ -207,6 +212,7 @@ HWTEST_F(TimeUtilsTest, testGmtimeR, Function | MediumTest | Level3)
time_t timeNow;
time(&timeNow);
stm = gmtime_r(&timeNow, &res);
ASSERT_NE(nullptr, stm);
EXPECT_EQ(stm->tm_year, 70) << "gmtime_r return error!";
EXPECT_STRNE(asctime(stm), "") << "gmtime_r return error!";
EXPECT_TRUE(stm == &res) << "gmtime_r returns not equal";
......
......@@ -455,7 +455,7 @@ void GetCameraId(CameraKit *cameraKit, list<string> &camList, string &camId)
for (auto &cam : camList) {
cout << "camera name:" << cam << endl;
const CameraAbility *ability = cameraKit->GetCameraAbility(cam);
EXPECT_NE(ability, nullptr);
ASSERT_NE(ability, nullptr);
CameraFlag::g_onGetCameraAbilityFlag = FLAG1;
/* find camera which fits user's ability */
list<CameraPicSize> sizeList = ability->GetSupportedSizes(0);
......@@ -572,7 +572,7 @@ HWTEST_F(ActsMediaCameraTest, Test_RegisterCameraDeviceCallback, Function | Medi
SampleCameraStateMng camStateMng(eventHdlr);
SampleCameraDeviceCallback *deviceCallback = nullptr;
deviceCallback = new SampleCameraDeviceCallback();
EXPECT_NE(nullptr, deviceCallback);
ASSERT_NE(nullptr, deviceCallback);
cameraKit->RegisterCameraDeviceCallback(*deviceCallback, eventHdlr);
sleep(1);
EXPECT_EQ(CameraFlag::g_onCameraAvailableFlag, FLAG1);
......@@ -596,7 +596,7 @@ HWTEST_F(ActsMediaCameraTest, Test_UnregisterCameraDeviceCallback, Function | Me
SampleCameraStateMng camStateMng(eventHdlr);
SampleCameraDeviceCallback *deviceCallback = nullptr;
deviceCallback = new SampleCameraDeviceCallback();
EXPECT_NE(nullptr, deviceCallback);
ASSERT_NE(nullptr, deviceCallback);
cameraKit->RegisterCameraDeviceCallback(*deviceCallback, eventHdlr);
sleep(1);
EXPECT_EQ(CameraFlag::g_onCameraAvailableFlag, FLAG1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册