refactor: rename testbench to test.
- rename testbench to test. - add benchmark for future development.
This commit is contained in:
24
test/yycc/patch/fopen.cpp
Normal file
24
test/yycc/patch/fopen.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/patch/fopen.hpp>
|
||||
|
||||
#define FOPEN ::yycc::patch::fopen
|
||||
|
||||
namespace yycctest::patch::fopen {
|
||||
|
||||
TEST(PatchFopen, Normal) {
|
||||
FILE* handle;
|
||||
|
||||
#if defined(YYCC_OS_WINDOWS)
|
||||
// In Windows, we can always visit NUL device.
|
||||
handle = FOPEN::fopen(u8"NUL", u8"wb");
|
||||
#else
|
||||
// In other system following UNIX design, we can visit /dev/null device.
|
||||
handle = FOPEN::fopen(u8"/dev/null", u8"wb");
|
||||
#endif
|
||||
|
||||
ASSERT_TRUE(handle != nullptr);
|
||||
std::fclose(handle);
|
||||
}
|
||||
|
||||
} // namespace yycctest::patch::fopen
|
35
test/yycc/patch/format.cpp
Normal file
35
test/yycc/patch/format.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/patch/format.hpp>
|
||||
|
||||
#define FORMAT ::yycc::patch::format
|
||||
|
||||
namespace yycctest::patch::format {
|
||||
|
||||
static constexpr char8_t PROBE[] = u8"hello";
|
||||
static std::u8string PROBE_STRING(PROBE);
|
||||
static constexpr std::u8string_view PROBE_STRING_VIEW(PROBE);
|
||||
|
||||
TEST(PatchFormat, OrdinaryFormat) {
|
||||
auto rv = FORMAT::format("{:c}{}{}{}{}{} world!",
|
||||
PROBE[0],
|
||||
PROBE_STRING.data(),
|
||||
PROBE_STRING.c_str(),
|
||||
PROBE,
|
||||
PROBE_STRING,
|
||||
PROBE_STRING_VIEW);
|
||||
EXPECT_EQ(rv, "hhellohellohellohellohello world!");
|
||||
}
|
||||
|
||||
TEST(PatchFormat, Utf8Format) {
|
||||
auto rv = FORMAT::format(u8"{:c}{}{}{}{}{} world!",
|
||||
PROBE[0],
|
||||
PROBE_STRING.data(),
|
||||
PROBE_STRING.c_str(),
|
||||
PROBE,
|
||||
PROBE_STRING,
|
||||
PROBE_STRING_VIEW);
|
||||
EXPECT_EQ(rv, u8"hhellohellohellohellohello world!");
|
||||
}
|
||||
|
||||
}
|
21
test/yycc/patch/ptr_pad.cpp
Normal file
21
test/yycc/patch/ptr_pad.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/string/op.hpp>
|
||||
#include <yycc/patch/ptr_pad.hpp>
|
||||
#include <cinttypes>
|
||||
|
||||
#define OP ::yycc::string::op
|
||||
|
||||
namespace yycctest::patch::ptr_pad {
|
||||
|
||||
TEST(PatchPtrPad, Normal) {
|
||||
auto rv = OP::printf(u8"0x%" PRIXPTR_LPAD PRIXPTR, nullptr);
|
||||
|
||||
#if defined(YYCC_PTRSIZE_32)
|
||||
EXPECT_EQ(rv, u8"0x00000000");
|
||||
#else
|
||||
EXPECT_EQ(rv, u8"0x0000000000000000");
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
31
test/yycc/patch/stream.cpp
Normal file
31
test/yycc/patch/stream.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/patch/stream.hpp>
|
||||
#include <yycc/string/reinterpret.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#define REINTERPRET ::yycc::string::reinterpret
|
||||
using namespace std::literals::string_view_literals;
|
||||
using namespace ::yycc::patch::stream;
|
||||
|
||||
namespace yycctest::patch::stream {
|
||||
|
||||
TEST(PatchStream, StringView) {
|
||||
std::stringstream ss;
|
||||
ss << u8"hello"sv;
|
||||
EXPECT_EQ(REINTERPRET::as_utf8_view(ss.view()), u8"hello"sv);
|
||||
}
|
||||
|
||||
TEST(PatchStream, CStrPtr) {
|
||||
std::stringstream ss;
|
||||
ss << u8"hello";
|
||||
EXPECT_EQ(REINTERPRET::as_utf8_view(ss.view()), u8"hello");
|
||||
}
|
||||
|
||||
TEST(PatchStream, Character) {
|
||||
std::stringstream ss;
|
||||
ss << u8'y';
|
||||
EXPECT_EQ(REINTERPRET::as_utf8_view(ss.view()), u8"y");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user