Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-olivier committed Jul 19, 2024
1 parent ed27053 commit 751167f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ std::string format_symbol(std::string input) {
replace_occurrences(input, "<struct ", "<");
replace_occurrences(input, ",struct ", ",");

replace_occurrences(input, "> >", ">>");
replace_occurrences(input, ">const", "> const");

add_space_after_comma(input);
Expand Down
17 changes: 9 additions & 8 deletions tests/lib.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <string>

#if defined(_WIN32) || defined(_WIN64)
#define LIB_EXPORT __declspec(dllexport)
Expand Down Expand Up @@ -38,20 +39,20 @@ namespace tools {
}

namespace string {
LIB_EXPORT void println(const std::string &str) {
std::cout << "ref: " << str << std::endl;
LIB_EXPORT std::string format(const std::string &str) {
return std::string("ref: ") + str;
}

LIB_EXPORT void println(std::string &&str) {
std::cout << "mov: " << str << std::endl;
LIB_EXPORT std::string format(std::string &&str) {
return std::string("mov: ") + str;
}

LIB_EXPORT void println(const unsigned int& val) {
std::cout << "ref: " << val << std::endl;
LIB_EXPORT std::string format(const unsigned int& val) {
return std::string("ref: ") + std::to_string(val);
}

LIB_EXPORT void println(const char *val) {
std::cout << "ptr: " << val << std::endl;
LIB_EXPORT std::string format(const char *str) {
return std::string("ptr: ") + str;
}
}
}
24 changes: 8 additions & 16 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,17 @@ TEST(cpp_symbols, basic_test) {

auto text = std::string("bla,bla,bla...");

testing::internal::CaptureStdout();
auto ptr_println = lib.get_function<void(std::string&&)>("tools::string::println(char const *)");
ptr_println(text.c_str());
EXPECT_EQ(testing::internal::GetCapturedStdout(), "ptr: \x1c" "bla,bla,bla...\n");
auto ptr_format = lib.get_function<std::string(const char *)>("tools::string::format(char const *)");
EXPECT_EQ(ptr_format(text.c_str()), std::string("ptr: bla,bla,bla..."));

testing::internal::CaptureStdout();
auto ref_println = lib.get_function<void(const std::string&)>("tools::string::println(std::basic_string<char, std::char_traits<char>, std::allocator<char>> const &)");
ref_println(text);
EXPECT_EQ(testing::internal::GetCapturedStdout(), "ref: bla,bla,bla...\n");
auto ref_format = lib.get_function<std::string(const std::string&)>("tools::string::format(std::basic_string<char, std::char_traits<char>, std::allocator<char>> const &)");
EXPECT_EQ(ref_format(text), std::string("ref: bla,bla,bla..."));

testing::internal::CaptureStdout();
auto mov_println = lib.get_function<void(std::string&&)>("tools::string::println(std::basic_string<char, std::char_traits<char>, std::allocator<char>> &&)");
mov_println(std::move(text));
EXPECT_EQ(testing::internal::GetCapturedStdout(), "mov: bla,bla,bla...\n");
auto mov_format = lib.get_function<std::string(std::string&&)>("tools::string::format(std::basic_string<char, std::char_traits<char>, std::allocator<char>> &&)");
EXPECT_EQ(mov_format(std::move(text)), std::string("mov: bla,bla,bla..."));

testing::internal::CaptureStdout();
auto int_ref_println = lib.get_function<void(const unsigned int&)>("tools::string::println(unsigned int const &)");
int_ref_println(123);
EXPECT_EQ(testing::internal::GetCapturedStdout(), "ref: 123\n");
auto int_ref_println = lib.get_function<std::string(const unsigned int&)>("tools::string::format(unsigned int const &)");
EXPECT_EQ(int_ref_println(123), std::string("ref: 123"));
}

int main(int ac, char **av) {
Expand Down

0 comments on commit 751167f

Please sign in to comment.