enh: coverage (#20307)
* enh: coverage * enh: coverage, atomic * fix: int to int8 error * enh: delete unused code
This commit is contained in:
parent
a01b611dfe
commit
957bf49f9a
|
@ -18,20 +18,6 @@
|
|||
#include <stdlib.h>
|
||||
#include "talgo.h"
|
||||
|
||||
#ifdef WINDOWS
|
||||
void swapStr(char* j, char* J, int width) {
|
||||
int i;
|
||||
char tmp;
|
||||
for (i = 0; i < width; i++) {
|
||||
tmp = *j;
|
||||
*j = *J;
|
||||
*J = tmp;
|
||||
j++;
|
||||
J++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t qsortHelper(const void* p1, const void* p2, const void* param) {
|
||||
__compar_fn_t comparFn = param;
|
||||
return comparFn(p1, p2);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#endif
|
||||
|
||||
void taosSsleep(int32_t s) {
|
||||
if (s < 0) return;
|
||||
#ifdef WINDOWS
|
||||
Sleep(1000 * s);
|
||||
#else
|
||||
|
@ -30,6 +31,7 @@ void taosSsleep(int32_t s) {
|
|||
}
|
||||
|
||||
void taosMsleep(int32_t ms) {
|
||||
if (ms < 0) return;
|
||||
#ifdef WINDOWS
|
||||
Sleep(ms);
|
||||
#else
|
||||
|
@ -38,6 +40,7 @@ void taosMsleep(int32_t ms) {
|
|||
}
|
||||
|
||||
void taosUsleep(int32_t us) {
|
||||
if (us < 0) return;
|
||||
#ifdef WINDOWS
|
||||
HANDLE timer;
|
||||
LARGE_INTEGER interval;
|
||||
|
|
|
@ -94,21 +94,21 @@ int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) {
|
|||
|
||||
return 0;
|
||||
|
||||
#if 0
|
||||
int32_t ucs4_max_len = bytes + 4;
|
||||
char *f1_mbs = taosMemoryCalloc(bytes, 1);
|
||||
char *f2_mbs = taosMemoryCalloc(bytes, 1);
|
||||
if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) {
|
||||
return -1;
|
||||
}
|
||||
int32_t ret = strcmp(f1_mbs, f2_mbs);
|
||||
taosMemoryFree(f1_mbs);
|
||||
taosMemoryFree(f2_mbs);
|
||||
return ret;
|
||||
#endif
|
||||
//#if 0
|
||||
// int32_t ucs4_max_len = bytes + 4;
|
||||
// char *f1_mbs = taosMemoryCalloc(bytes, 1);
|
||||
// char *f2_mbs = taosMemoryCalloc(bytes, 1);
|
||||
// if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) {
|
||||
// return -1;
|
||||
// }
|
||||
// if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) {
|
||||
// return -1;
|
||||
// }
|
||||
// int32_t ret = strcmp(f1_mbs, f2_mbs);
|
||||
// taosMemoryFree(f1_mbs);
|
||||
// taosMemoryFree(f2_mbs);
|
||||
// return ret;
|
||||
//#endif
|
||||
}
|
||||
|
||||
TdUcs4 *tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4) {
|
||||
|
|
|
@ -17,8 +17,64 @@ INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
|
|||
|
||||
# osTests
|
||||
add_executable(osTests "osTests.cpp")
|
||||
target_link_libraries(osTests os util gtest_main)
|
||||
target_link_libraries(osTests os util gtest_main)
|
||||
add_test(
|
||||
NAME osTests
|
||||
COMMAND osTests
|
||||
)
|
||||
|
||||
add_executable(osSystemTests "osSystemTests.cpp")
|
||||
target_link_libraries(osSystemTests os util gtest_main)
|
||||
add_test(
|
||||
NAME osSystemTests
|
||||
COMMAND osSystemTests
|
||||
)
|
||||
|
||||
add_executable(osMathTests "osMathTests.cpp")
|
||||
target_link_libraries(osMathTests os util gtest_main)
|
||||
add_test(
|
||||
NAME osMathTests
|
||||
COMMAND osMathTests
|
||||
)
|
||||
|
||||
add_executable(osSignalTests "osSignalTests.cpp")
|
||||
target_link_libraries(osSignalTests os util gtest_main)
|
||||
add_test(
|
||||
NAME osSignalTests
|
||||
COMMAND osSignalTests
|
||||
)
|
||||
|
||||
add_executable(osSleepTests "osSleepTests.cpp")
|
||||
target_link_libraries(osSleepTests os util gtest_main)
|
||||
add_test(
|
||||
NAME osSleepTests
|
||||
COMMAND osSleepTests
|
||||
)
|
||||
|
||||
add_executable(osStringTests "osStringTests.cpp")
|
||||
target_link_libraries(osStringTests os util gtest_main)
|
||||
add_test(
|
||||
NAME osStringTests
|
||||
COMMAND osStringTests
|
||||
)
|
||||
|
||||
add_executable(osThreadTests "osThreadTests.cpp")
|
||||
target_link_libraries(osThreadTests os util gtest_main)
|
||||
add_test(
|
||||
NAME osThreadTests
|
||||
COMMAND osThreadTests
|
||||
)
|
||||
|
||||
add_executable(osTimeTests "osTimeTests.cpp")
|
||||
target_link_libraries(osTimeTests os util gtest_main)
|
||||
add_test(
|
||||
NAME osTimeTests
|
||||
COMMAND osTimeTests
|
||||
)
|
||||
|
||||
add_executable(osAtomicTests "osAtomicTests.cpp")
|
||||
target_link_libraries(osAtomicTests os util gtest_main)
|
||||
add_test(
|
||||
NAME osAtomicTests
|
||||
COMMAND osAtomicTests
|
||||
)
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
|
||||
TEST(osAtomicTests, Exchange16) {
|
||||
int16_t value = 123;
|
||||
int16_t new_value = 456;
|
||||
int16_t result = atomic_exchange_16(&value, new_value);
|
||||
EXPECT_EQ(result, 123);
|
||||
EXPECT_EQ(value, 456);
|
||||
}
|
||||
|
||||
TEST(osAtomicTests, Exchange32) {
|
||||
int32_t value = 123;
|
||||
int32_t new_value = 456;
|
||||
int32_t result = atomic_exchange_32(&value, new_value);
|
||||
EXPECT_EQ(result, 123);
|
||||
EXPECT_EQ(value, 456);
|
||||
}
|
||||
|
||||
TEST(osAtomicTests, Exchange64) {
|
||||
int64_t value = 123;
|
||||
int64_t new_value = 456;
|
||||
int64_t result = atomic_exchange_64(&value, new_value);
|
||||
EXPECT_EQ(result, 123);
|
||||
EXPECT_EQ(value, 456);
|
||||
}
|
||||
|
||||
TEST(osAtomicTests, ExchangePtr) {
|
||||
int value1 = 123;
|
||||
int value2 = 456;
|
||||
int* ptr = &value1;
|
||||
int* result = (int*)atomic_exchange_ptr(&ptr, &value2);
|
||||
EXPECT_EQ(result, &value1);
|
||||
EXPECT_EQ(*ptr, 456);
|
||||
}
|
||||
|
||||
TEST(osAtomicTests, ValCompareExchange8) {
|
||||
int8_t value = 12;
|
||||
int8_t oldval = 12;
|
||||
int8_t newval = 45;
|
||||
int8_t result = atomic_val_compare_exchange_8(&value, oldval, newval);
|
||||
EXPECT_EQ(result, 12);
|
||||
EXPECT_EQ(value, 45);
|
||||
|
||||
oldval = 78;
|
||||
result = atomic_val_compare_exchange_8(&value, oldval, newval);
|
||||
EXPECT_EQ(result, 45);
|
||||
EXPECT_EQ(value, 45);
|
||||
}
|
||||
|
||||
TEST(osAtomicTests, ValCompareExchange16) {
|
||||
int16_t value = 123;
|
||||
int16_t oldval = 123;
|
||||
int16_t newval = 456;
|
||||
int16_t result = atomic_val_compare_exchange_16(&value, oldval, newval);
|
||||
EXPECT_EQ(result, 123);
|
||||
EXPECT_EQ(value, 456);
|
||||
|
||||
oldval = 789;
|
||||
result = atomic_val_compare_exchange_16(&value, oldval, newval);
|
||||
EXPECT_EQ(result, 456);
|
||||
EXPECT_EQ(value, 456);
|
||||
}
|
||||
|
||||
TEST(osAtomicTests, TestAtomicExchange8) {
|
||||
volatile int8_t value = 42;
|
||||
int8_t new_value = 100;
|
||||
int8_t old_value = atomic_exchange_8(&value, new_value);
|
||||
EXPECT_EQ(old_value, 42);
|
||||
EXPECT_EQ(value, new_value);
|
||||
}
|
||||
|
||||
TEST(osAtomicTests, TestAtomicAddFetch16) {
|
||||
volatile int16_t value = 42;
|
||||
int16_t increment = 10;
|
||||
int16_t new_value = atomic_add_fetch_16(&value, increment);
|
||||
EXPECT_EQ(new_value, 52);
|
||||
EXPECT_EQ(value, 52);
|
||||
}
|
||||
|
||||
//TEST(osAtomicTests, AddFetchPtr) {
|
||||
// uintptr_t val = 0;
|
||||
// uintptr_t* ptr = &val;
|
||||
// uintptr_t ret = atomic_add_fetch_ptr(ptr, 10);
|
||||
// EXPECT_EQ(ret, 10);
|
||||
// EXPECT_EQ(val, 10);
|
||||
//}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
|
||||
struct TestStruct {
|
||||
int a;
|
||||
float b;
|
||||
};
|
||||
|
||||
// Define a custom comparison function for testing
|
||||
int cmpFunc(const void* a, const void* b) {
|
||||
const TestStruct* pa = reinterpret_cast<const TestStruct*>(a);
|
||||
const TestStruct* pb = reinterpret_cast<const TestStruct*>(b);
|
||||
if (pa->a < pb->a) {
|
||||
return -1;
|
||||
} else if (pa->a > pb->a) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(osMathTests, taosSort) {
|
||||
// Create an array of test data
|
||||
TestStruct arr[] = {{4, 2.5}, {2, 1.5}, {1, 3.5}, {3, 4.5}};
|
||||
|
||||
// Sort the array using taosSort
|
||||
taosSort(arr, 4, sizeof(TestStruct), cmpFunc);
|
||||
|
||||
// Check that the array is sorted correctly
|
||||
EXPECT_EQ(arr[0].a, 1);
|
||||
EXPECT_EQ(arr[1].a, 2);
|
||||
EXPECT_EQ(arr[2].a, 3);
|
||||
EXPECT_EQ(arr[3].a, 4);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
|
||||
TEST(osSignalTests, taosSetSignal) {
|
||||
// Set up SIGINT handler using taosSetSignal
|
||||
//taosSetSignal(SIGINT, sigint_handler);
|
||||
|
||||
// Print PID for testing purposes
|
||||
// printf("PID: %d\n", getpid());
|
||||
|
||||
// Wait for signal to be received
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
|
||||
TEST(osSleepTests, taosUsleep) {
|
||||
const int sleep_time1 = 1000; // sleep for 1000 microseconds
|
||||
taosUsleep(sleep_time1);
|
||||
|
||||
const int sleep_time2 = 0; // sleep for 0 microseconds
|
||||
taosUsleep(sleep_time2);
|
||||
|
||||
const int sleep_time3 = -1; // sleep for negative time
|
||||
taosUsleep(sleep_time3);
|
||||
}
|
||||
|
||||
TEST(osSleepTests, taosSsleep) {
|
||||
const int sleep_time1 = 1;
|
||||
taosSsleep(sleep_time1);
|
||||
|
||||
const int sleep_time2 = 0;
|
||||
taosSsleep(sleep_time2);
|
||||
|
||||
const int sleep_time3 = -1;
|
||||
taosSsleep(sleep_time3);
|
||||
}
|
||||
|
||||
TEST(osSleepTests, taosMsleep) {
|
||||
const int sleep_time1 = 1000;
|
||||
taosMsleep(sleep_time1);
|
||||
|
||||
const int sleep_time2 = 0;
|
||||
taosMsleep(sleep_time2);
|
||||
|
||||
const int sleep_time3 = -1; // sleep for negative time
|
||||
taosMsleep(sleep_time3);
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
|
||||
#ifdef WINDOWS
|
||||
TEST(osStringTests, strsepNormalInput) {
|
||||
char str[] = "This is a test string.";
|
||||
char * ptr = str;
|
||||
char * tok = NULL;
|
||||
const char delim[] = " ";
|
||||
|
||||
while ((tok = strsep(&ptr, delim)) != NULL) {
|
||||
printf("%s\n", tok);
|
||||
}
|
||||
EXPECT_STREQ(tok, nullptr);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST(osStringTests, strsepEmptyInput) {
|
||||
char* str = "";
|
||||
char* ptr = str;
|
||||
char* tok = NULL;
|
||||
const char delim[] = " ";
|
||||
|
||||
while ((tok = strsep(&ptr, delim)) != NULL) {
|
||||
printf("%s\n", tok);
|
||||
}
|
||||
|
||||
EXPECT_STREQ(tok, nullptr);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST(osStringTests, strsepNullInput) {
|
||||
char * str = NULL;
|
||||
char * ptr = str;
|
||||
char * tok = NULL;
|
||||
const char delim[] = " ";
|
||||
|
||||
while ((tok = strsep(&ptr, delim)) != NULL) {
|
||||
printf("%s\n", tok);
|
||||
}
|
||||
|
||||
EXPECT_STREQ(tok, nullptr);
|
||||
EXPECT_EQ(ptr, nullptr);
|
||||
}
|
||||
|
||||
TEST(osStringTests, strndupNormalInput) {
|
||||
const char s[] = "This is a test string.";
|
||||
int size = strlen(s) + 1;
|
||||
char * s2 = strndup(s, size);
|
||||
|
||||
EXPECT_STREQ(s, s2);
|
||||
|
||||
free(s2);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(osStringTests, osUcs4Tests1) {
|
||||
TdUcs4 f1_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0000};
|
||||
TdUcs4 f2_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0000};
|
||||
|
||||
EXPECT_EQ(tasoUcs4Compare(f1_ucs4, f2_ucs4, sizeof(f1_ucs4)), 0);
|
||||
|
||||
TdUcs4 f3_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0020, 0x0077,
|
||||
0x006F, 0x0072, 0x006C, 0x0064, 0x0021, 0x0000};
|
||||
TdUcs4 f4_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0000};
|
||||
|
||||
EXPECT_GT(tasoUcs4Compare(f3_ucs4, f4_ucs4, sizeof(f3_ucs4)), 0);
|
||||
|
||||
TdUcs4 f5_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0000};
|
||||
TdUcs4 f6_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0020, 0x0077,
|
||||
0x006F, 0x0072, 0x006C, 0x0064, 0x0021, 0x0000};
|
||||
|
||||
EXPECT_LT(tasoUcs4Compare(f5_ucs4, f6_ucs4, sizeof(f5_ucs4)), 0);
|
||||
}
|
||||
|
||||
TEST(osStringTests, osUcs4lenTests2) {
|
||||
TdUcs4 ucs4_1[] = {'H', 'e', 'l', 'l', 'o', '\0'};
|
||||
EXPECT_EQ(taosUcs4len(ucs4_1), 5);
|
||||
|
||||
TdUcs4 ucs4_2[] = {'\0'};
|
||||
EXPECT_EQ(taosUcs4len(ucs4_2), 0);
|
||||
|
||||
TdUcs4 ucs4_3[] = {'C', 'h', 'i', 'n', 'a', 0x4E2D, 0x6587, '\0'};
|
||||
EXPECT_EQ(taosUcs4len(ucs4_3), 7);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
|
||||
TEST(osSystemTest, osSystem1) {
|
||||
char tmp[4096] = "test";
|
||||
#ifdef _TD_DARWIN_64
|
||||
taosLogTraceToBuf(tmp, sizeof(tmp), 4);
|
||||
#elif !defined(WINDOWS)
|
||||
taosLogTraceToBuf(tmp, sizeof(tmp), 3);
|
||||
#else
|
||||
taosLogTraceToBuf(tmp, sizeof(tmp), 8);
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
|
||||
TEST(osThreadTests, osThreadTests1) {
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
|
||||
#pragma GCC diagnostic ignored "-Wpointer-arith"
|
||||
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
|
||||
TEST(osTimeTests, taosLocalTimeNolock) {
|
||||
time_t currentTime;
|
||||
// Test when result is NULL
|
||||
struct tm* result = taosLocalTimeNolock(NULL, ¤tTime, 0);
|
||||
// Test when result is not NULL
|
||||
struct tm expectedTime;
|
||||
result = taosLocalTimeNolock(&expectedTime, ¤tTime, 1);
|
||||
EXPECT_EQ(expectedTime.tm_year, result->tm_year);
|
||||
EXPECT_EQ(expectedTime.tm_mon, result->tm_mon);
|
||||
EXPECT_EQ(expectedTime.tm_mday, result->tm_mday);
|
||||
EXPECT_EQ(expectedTime.tm_hour, result->tm_hour);
|
||||
EXPECT_EQ(expectedTime.tm_min, result->tm_min);
|
||||
EXPECT_EQ(expectedTime.tm_sec, result->tm_sec);
|
||||
EXPECT_EQ(expectedTime.tm_wday, result->tm_wday);
|
||||
EXPECT_EQ(expectedTime.tm_yday, result->tm_yday);
|
||||
EXPECT_EQ(expectedTime.tm_isdst, result->tm_isdst);
|
||||
}
|
Loading…
Reference in New Issue