aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcherednik <dcherednik@ydb.tech>2023-03-10 15:39:40 +0300
committerdcherednik <dcherednik@ydb.tech>2023-03-10 15:39:40 +0300
commit3c4e50751cbe95a6e55c69ce26159de97fdc9a74 (patch)
tree9d7eac8891f5e3a110fb96b32a3b5a9a91730ed4
parent394219e982f65dd1ab4e4511051f4c97011c8712 (diff)
downloadydb-3c4e50751cbe95a6e55c69ce26159de97fdc9a74.tar.gz
Add macro for ut -> gtest replcement.
-rw-r--r--ydb/library/testlib/CMakeLists.txt1
-rw-r--r--ydb/library/testlib/unittest_gtest_macro_subst.h35
-rw-r--r--ydb/library/testlib/ut/CMakeLists.darwin-x86_64.txt34
-rw-r--r--ydb/library/testlib/ut/CMakeLists.linux-aarch64.txt38
-rw-r--r--ydb/library/testlib/ut/CMakeLists.linux-x86_64.txt40
-rw-r--r--ydb/library/testlib/ut/CMakeLists.txt17
-rw-r--r--ydb/library/testlib/ut/CMakeLists.windows-x86_64.txt28
-rw-r--r--ydb/library/testlib/ut/gtest_compat_ut.cpp43
8 files changed, 229 insertions, 7 deletions
diff --git a/ydb/library/testlib/CMakeLists.txt b/ydb/library/testlib/CMakeLists.txt
index d3c98b6b3ae..66e6d3a7a9c 100644
--- a/ydb/library/testlib/CMakeLists.txt
+++ b/ydb/library/testlib/CMakeLists.txt
@@ -7,3 +7,4 @@
add_subdirectory(service_mocks)
+add_subdirectory(ut)
diff --git a/ydb/library/testlib/unittest_gtest_macro_subst.h b/ydb/library/testlib/unittest_gtest_macro_subst.h
index e3154b86a38..ecec50341bc 100644
--- a/ydb/library/testlib/unittest_gtest_macro_subst.h
+++ b/ydb/library/testlib/unittest_gtest_macro_subst.h
@@ -1,9 +1,30 @@
// Macro substitutions for tests converted from Unittest to GTest
-#define UNIT_ASSERT( condition ) ASSERT_TRUE( condition )
-#define UNIT_ASSERT_C( condition, comment ) ASSERT_TRUE( condition ) << comment
-#define UNIT_ASSERT_STRINGS_EQUAL( p1, p2 ) ASSERT_EQ( p1, p2 )
-#define UNIT_ASSERT_EQUAL( p1, p2 ) ASSERT_EQ( p1, p2 )
-#define UNIT_ASSERT_EQUAL_C( p1, p2, comment ) ASSERT_EQ( p1, p2 ) << comment
-#define UNIT_ASSERT_UNEQUAL( p1, p2 ) ASSERT_NE( p1, p2 )
-#define UNIT_ASSERT_UNEQUAL_C( p1, p2, comment ) ASSERT_NE( p1, p2 ) << comment \ No newline at end of file
+inline void DoUnitAssertValEqual(const char* s1, const char* s2) {
+ ASSERT_STREQ(s1, s2);
+}
+
+template <typename T1, typename T2>
+inline void DoUnitAssertValEqual(const T1& s1, const T2& s2) {
+ ASSERT_EQ(s1, s2);
+}
+
+inline void DoUnitAssertValUnEqual(const char* s1, const char* s2) {
+ ASSERT_STRNE(s1, s2);
+}
+
+template <typename T1, typename T2>
+inline void DoUnitAssertValUnEqual(const T1& s1, const T2& s2) {
+ ASSERT_NE(s1, s2);
+}
+
+#define UNIT_ASSERT( condition ) ASSERT_TRUE( condition )
+#define UNIT_ASSERT_C( condition, comment ) ASSERT_TRUE( condition ) << comment
+#define UNIT_ASSERT_STRINGS_EQUAL( p1, p2 ) do { DoUnitAssertValEqual(p1, p2); } while (0);
+#define UNIT_ASSERT_VALUES_EQUAL( p1, p2) do { DoUnitAssertValEqual(p1, p2); } while (0);
+#define UNIT_ASSERT_STRINGS_UNEQUAL( p1, p2 ) do { DoUnitAssertValUnEqual(p1, p2); } while (0);
+#define UNIT_ASSERT_VALUES_UNEQUAL( p1, p2) do { DoUnitAssertValUnEqual(p1, p2); } while (0);
+#define UNIT_ASSERT_EQUAL( p1, p2 ) ASSERT_EQ( p1, p2 )
+#define UNIT_ASSERT_EQUAL_C( p1, p2, comment ) ASSERT_EQ( p1, p2 ) << comment
+#define UNIT_ASSERT_UNEQUAL( p1, p2 ) ASSERT_NE( p1, p2 )
+#define UNIT_ASSERT_UNEQUAL_C( p1, p2, comment ) ASSERT_NE( p1, p2 ) << comment
diff --git a/ydb/library/testlib/ut/CMakeLists.darwin-x86_64.txt b/ydb/library/testlib/ut/CMakeLists.darwin-x86_64.txt
new file mode 100644
index 00000000000..f11c31a71ef
--- /dev/null
+++ b/ydb/library/testlib/ut/CMakeLists.darwin-x86_64.txt
@@ -0,0 +1,34 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_executable(ydb-library-testlib-ut)
+target_link_libraries(ydb-library-testlib-ut PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ cpp-malloc-system
+ library-cpp-cpuid_check
+ cpp-testing-gtest
+ cpp-testing-gtest_main
+)
+target_link_options(ydb-library-testlib-ut PRIVATE
+ -Wl,-no_deduplicate
+ -Wl,-sdk_version,10.15
+ -fPIC
+ -fPIC
+)
+target_sources(ydb-library-testlib-ut PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/library/testlib/ut/gtest_compat_ut.cpp
+)
+add_test(
+ NAME
+ ydb-library-testlib-ut
+ COMMAND
+ ydb-library-testlib-ut
+)
+vcs_info(ydb-library-testlib-ut)
diff --git a/ydb/library/testlib/ut/CMakeLists.linux-aarch64.txt b/ydb/library/testlib/ut/CMakeLists.linux-aarch64.txt
new file mode 100644
index 00000000000..9e9d8ab93d1
--- /dev/null
+++ b/ydb/library/testlib/ut/CMakeLists.linux-aarch64.txt
@@ -0,0 +1,38 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_executable(ydb-library-testlib-ut)
+target_link_libraries(ydb-library-testlib-ut PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ library-cpp-lfalloc
+ cpp-testing-gtest
+ cpp-testing-gtest_main
+)
+target_link_options(ydb-library-testlib-ut PRIVATE
+ -ldl
+ -lrt
+ -Wl,--no-as-needed
+ -fPIC
+ -fPIC
+ -lpthread
+ -lrt
+ -ldl
+)
+target_sources(ydb-library-testlib-ut PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/library/testlib/ut/gtest_compat_ut.cpp
+)
+add_test(
+ NAME
+ ydb-library-testlib-ut
+ COMMAND
+ ydb-library-testlib-ut
+)
+vcs_info(ydb-library-testlib-ut)
diff --git a/ydb/library/testlib/ut/CMakeLists.linux-x86_64.txt b/ydb/library/testlib/ut/CMakeLists.linux-x86_64.txt
new file mode 100644
index 00000000000..913a2ceae69
--- /dev/null
+++ b/ydb/library/testlib/ut/CMakeLists.linux-x86_64.txt
@@ -0,0 +1,40 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_executable(ydb-library-testlib-ut)
+target_link_libraries(ydb-library-testlib-ut PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ cpp-malloc-tcmalloc
+ libs-tcmalloc-no_percpu_cache
+ library-cpp-cpuid_check
+ cpp-testing-gtest
+ cpp-testing-gtest_main
+)
+target_link_options(ydb-library-testlib-ut PRIVATE
+ -ldl
+ -lrt
+ -Wl,--no-as-needed
+ -fPIC
+ -fPIC
+ -lpthread
+ -lrt
+ -ldl
+)
+target_sources(ydb-library-testlib-ut PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/library/testlib/ut/gtest_compat_ut.cpp
+)
+add_test(
+ NAME
+ ydb-library-testlib-ut
+ COMMAND
+ ydb-library-testlib-ut
+)
+vcs_info(ydb-library-testlib-ut)
diff --git a/ydb/library/testlib/ut/CMakeLists.txt b/ydb/library/testlib/ut/CMakeLists.txt
new file mode 100644
index 00000000000..d90657116d0
--- /dev/null
+++ b/ydb/library/testlib/ut/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND UNIX AND NOT APPLE AND NOT ANDROID)
+ include(CMakeLists.linux-aarch64.txt)
+elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ include(CMakeLists.darwin-x86_64.txt)
+elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" AND NOT HAVE_CUDA)
+ include(CMakeLists.windows-x86_64.txt)
+elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE AND NOT ANDROID AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-x86_64.txt)
+endif()
diff --git a/ydb/library/testlib/ut/CMakeLists.windows-x86_64.txt b/ydb/library/testlib/ut/CMakeLists.windows-x86_64.txt
new file mode 100644
index 00000000000..9c997ce21e1
--- /dev/null
+++ b/ydb/library/testlib/ut/CMakeLists.windows-x86_64.txt
@@ -0,0 +1,28 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_executable(ydb-library-testlib-ut)
+target_link_libraries(ydb-library-testlib-ut PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ cpp-malloc-system
+ library-cpp-cpuid_check
+ cpp-testing-gtest
+ cpp-testing-gtest_main
+)
+target_sources(ydb-library-testlib-ut PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/library/testlib/ut/gtest_compat_ut.cpp
+)
+add_test(
+ NAME
+ ydb-library-testlib-ut
+ COMMAND
+ ydb-library-testlib-ut
+)
+vcs_info(ydb-library-testlib-ut)
diff --git a/ydb/library/testlib/ut/gtest_compat_ut.cpp b/ydb/library/testlib/ut/gtest_compat_ut.cpp
new file mode 100644
index 00000000000..23b090e4df9
--- /dev/null
+++ b/ydb/library/testlib/ut/gtest_compat_ut.cpp
@@ -0,0 +1,43 @@
+#include <library/cpp/testing/gtest/gtest.h>
+#include <ydb/library/testlib/unittest_gtest_macro_subst.h>
+
+namespace {
+ TEST(TestForTest, AssertTrue) {
+ UNIT_ASSERT(true);
+ }
+
+ TEST(TestForTest, AssertTStringEqual) {
+ TString s1 = "q";
+ TString s2 = "q";
+ UNIT_ASSERT_EQUAL(s1, s2);
+ UNIT_ASSERT_STRINGS_EQUAL(s1, s2);
+ UNIT_ASSERT_VALUES_EQUAL(s1, s2);
+ }
+
+ TEST(TestForTest, AssertCCharNotEqualLocation) {
+ const char* s1 = "1q";
+ const char* s2 = "2q";
+ UNIT_ASSERT_UNEQUAL(s1, s2);
+ UNIT_ASSERT_STRINGS_UNEQUAL(s1, s2);
+ UNIT_ASSERT_VALUES_UNEQUAL(s1, s2);
+ s1++;
+ s2++;
+ // different address location
+ UNIT_ASSERT_UNEQUAL(s1, s2);
+ // but same value
+ UNIT_ASSERT_STRINGS_EQUAL(s1, s2);
+ UNIT_ASSERT_VALUES_EQUAL(s1, s2);
+ }
+
+ TEST(TestForTest, AssertCCharEqualLocation) {
+ static const char* buf = "str";
+ const char* s1 = buf;
+ const char* s2 = buf;
+ // same address location
+ UNIT_ASSERT_EQUAL(s1, s2);
+ // same value
+ UNIT_ASSERT_STRINGS_EQUAL(s1, s2);
+ UNIT_ASSERT_VALUES_EQUAL(s1, s2);
+ }
+}
+