test: add testbench for macro namespace

This commit is contained in:
2025-08-15 16:55:39 +08:00
parent 2f11ba6023
commit dfc0c127c5
7 changed files with 107 additions and 6 deletions

View File

@ -17,9 +17,9 @@ namespace yycc::macro::stl {
/// @brief The STL implementation kind.
enum class StlKind {
MSSTL, ///< Microsoft STL
GNUSTL, ///< GNU STL
CLANGSTL ///< Clang STL
MsStl, ///< Microsoft STL
GnuStl, ///< GNU STL
ClangStl ///< Clang STL
};
/**
@ -28,11 +28,11 @@ namespace yycc::macro::stl {
*/
inline constexpr StlKind get_stl() {
#if defined(YYCC_STL_MSSTL)
return StlKind::MSSTL;
return StlKind::MsStl;
#elif defined(YYCC_STL_GNUSTL)
return StlKind::GNUSTL;
return StlKind::GnuStl;
#else
return StlKind::CLANGSTL;
return StlKind::ClangStl;
#endif
}

View File

@ -7,6 +7,11 @@ PRIVATE
main.cpp
yycc/macro/version_cmp.cpp
yycc/macro/os_detector.cpp
yycc/macro/compiler_detector.cpp
yycc/macro/endian_detector.cpp
yycc/macro/ptr_size_detector.cpp
yycc/macro/stl_detector.cpp
yycc/flag_enum.cpp
yycc/constraint.cpp
yycc/constraint/builder.cpp

View File

@ -0,0 +1,20 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/macro/compiler_detector.hpp>
#define COMPILER ::yycc::macro::compiler
namespace yycctest::macro::compiler {
TEST(MacroCompiler, Main) {
auto rv = COMPILER::get_compiler();
#if defined(YYCC_CC_MSVC)
EXPECT_EQ(rv, COMPILER::CompilerKind::Msvc);
#elif defined(YYCC_CC_GCC)
EXPECT_EQ(rv, COMPILER::CompilerKind::Gcc);
#else
EXPECT_EQ(rv, COMPILER::CompilerKind::Clang);
#endif
}
} // namespace yycctest::macro::compiler

View File

@ -0,0 +1,18 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/macro/endian_detector.hpp>
#define ENDIAN ::yycc::macro::endian
namespace yycctest::macro::endian {
TEST(MacroEndian, Main) {
auto rv = ENDIAN::get_endian();
#if defined(YYCC_ENDIAN_LITTLE)
EXPECT_EQ(rv, ENDIAN::EndianKind::Little);
#else
EXPECT_EQ(rv, ENDIAN::EndianKind::Big);
#endif
}
} // namespace yycctest::macro::endian

View File

@ -0,0 +1,20 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/macro/os_detector.hpp>
#define OS ::yycc::macro::os
namespace yycctest::macro::os {
TEST(MacroOs, Main) {
auto rv = OS::get_os();
#if defined(YYCC_OS_WINDOWS)
EXPECT_EQ(rv, OS::OsKind::Windows);
#elif defined(YYCC_OS_LINUX)
EXPECT_EQ(rv, OS::OsKind::Linux);
#else
EXPECT_EQ(rv, OS::OsKind::MacOs);
#endif
}
} // namespace yycctest::macro::os

View File

@ -0,0 +1,18 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/macro/ptr_size_detector.hpp>
#define PTR_SIZE ::yycc::macro::ptr_size
namespace yycctest::macro::ptr_size {
TEST(MacroPtrSize, Main) {
auto rv = PTR_SIZE::get_ptr_size();
#if defined(YYCC_PTRSIZE_32)
EXPECT_EQ(rv, PTR_SIZE::PtrSizeKind::Bits32);
#else
EXPECT_EQ(rv, PTR_SIZE::PtrSizeKind::Bits64);
#endif
}
} // namespace yycctest::macro::ptr_size

View File

@ -0,0 +1,20 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/macro/stl_detector.hpp>
#define STL ::yycc::macro::stl
namespace yycctest::macro::stl {
TEST(MacroStl, Main) {
auto rv = STL::get_stl();
#if defined(YYCC_STL_MSSTL)
EXPECT_EQ(rv, STL::StlKind::MsStl);
#elif defined(YYCC_STL_GNUSTL)
EXPECT_EQ(rv, STL::StlKind::GnuStl);
#else
EXPECT_EQ(rv, STL::StlKind::ClangStl);
#endif
}
} // namespace yycctest::macro::stl