-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Test coverage for console component
- Loading branch information
Showing
9 changed files
with
252 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (C) 2022 TiltedPhoques SRL. | ||
// For licensing information see LICENSE at the root of this distribution. | ||
|
||
#include <gtest/gtest.h> | ||
#include <spdlog/spdlog-inl.h> | ||
#include <spdlog/sinks/stdout_color_sinks.h> | ||
#include <console/ConsoleRegistry.h> | ||
|
||
namespace console | ||
{ | ||
namespace | ||
{ | ||
class ConsoleRegistryTest : public ::testing::Test | ||
{ | ||
public: | ||
void SetUp() override; | ||
void TearDown() override; | ||
|
||
private: | ||
}; | ||
|
||
void ConsoleRegistryTest::SetUp() | ||
{ | ||
spdlog::stdout_color_mt("Test"); | ||
} | ||
|
||
void ConsoleRegistryTest::TearDown() | ||
{ | ||
spdlog::drop("Test"); | ||
} | ||
|
||
TEST_F(ConsoleRegistryTest, RegisterCommand) | ||
{ | ||
// "static" command | ||
Command<int> sc{"test0", "desc", [&](ArgStack& stack) { | ||
EXPECT_EQ(stack.Pop<int>(), 7); | ||
}}; | ||
|
||
// "static" setting | ||
Setting<bool> ss{"test0", "", true, SettingBase::Flags::kLocked}; | ||
|
||
ConsoleRegistry r("Test"); | ||
r.RegisterCommand<bool, bool>("name", "description", [&](ArgStack& stack) { | ||
EXPECT_TRUE(stack.Pop<bool>()); | ||
EXPECT_FALSE(stack.Pop<bool>()); | ||
}); | ||
|
||
ASSERT_TRUE(r.FindCommand("name")); | ||
|
||
r.TryExecuteCommand("/name true false"); | ||
r.TryExecuteCommand("/test0 7"); | ||
r.TryExecuteCommand("/test0 10 10 10"); | ||
r.TryExecuteCommand("/test0 true"); | ||
|
||
r.RegisterSetting<bool>("name", "desc", false); | ||
ASSERT_TRUE(r.FindSetting("name")); | ||
ASSERT_TRUE(r.FindSetting("test0")); | ||
|
||
// FAIL | ||
r.TryExecuteCommand("test0 7"); | ||
r.TryExecuteCommand("/test \xe2\x28\xa1"); | ||
} | ||
|
||
TEST_F(ConsoleRegistryTest, RegisterSetting) | ||
{ | ||
// ConsoleRegistry r("Test"); | ||
// r.RegisterSetting<bool>("name", "desc", false); | ||
|
||
//ASSERT_TRUE(r.FindSetting("name")); | ||
} | ||
} // namespace | ||
} // namespace console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (C) 2022 TiltedPhoques SRL. | ||
// For licensing information see LICENSE at the root of this distribution. | ||
|
||
#include <gtest/gtest.h> | ||
#include <console/ConsoleUtils.h> | ||
|
||
namespace console | ||
{ | ||
namespace | ||
{ | ||
TEST(ConsoleUtils, TestUTF8) | ||
{ | ||
EXPECT_TRUE(CheckIsValidUTF8("A Quick brown fox jumps over the fence")); | ||
EXPECT_FALSE(CheckIsValidUTF8("\xe2\x28\xa1")); | ||
} | ||
|
||
TEST(ConsoleUtils, TestNumeric) | ||
{ | ||
EXPECT_TRUE(IsNumber("10")); | ||
EXPECT_TRUE(IsNumber("10.00")); | ||
|
||
// German way is not supported yet. | ||
//EXPECT_TRUE(IsNumber("10,00")); | ||
|
||
EXPECT_FALSE(IsNumber("ten")); | ||
EXPECT_FALSE(IsNumber("ten100")); | ||
EXPECT_FALSE(IsNumber("ten10,0")); | ||
EXPECT_FALSE(IsNumber("ten10.0")); | ||
EXPECT_FALSE(IsNumber("ten 10.0 10")); | ||
} | ||
} // namespace | ||
} // namespace console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (C) 2022 TiltedPhoques SRL. | ||
// For licensing information see LICENSE at the root of this distribution. | ||
|
||
#include <gtest/gtest.h> | ||
#include <console/StringTokenizer.h> | ||
|
||
namespace console | ||
{ | ||
namespace | ||
{ | ||
TEST(StringTokenizer, Count) | ||
{ | ||
{ | ||
StringTokenizer t("A Quick brown fox jumps over the fence"); | ||
EXPECT_EQ(t.CountTokens(), 8); | ||
} | ||
|
||
{ | ||
StringTokenizer t("A_Quick brown fox_jumps over the fence"); | ||
EXPECT_EQ(t.CountTokens(), 6); | ||
} | ||
|
||
{ | ||
StringTokenizer t("A Quick brown\nfox jumps\rover the fence"); | ||
EXPECT_EQ(t.CountTokens(), 8); | ||
} | ||
} | ||
|
||
TEST(StringTokenizer, Tokinize) | ||
{ | ||
{ | ||
StringTokenizer t("A Quick brown fox jumps over the fence"); | ||
|
||
std::vector<std::string> vec; | ||
while (t.HasMore()) | ||
t.GetNext(vec.emplace_back()); | ||
|
||
EXPECT_EQ(vec.size(), 8); | ||
} | ||
|
||
{ | ||
StringTokenizer t("A_Quick brown fox_jumps over the fence"); | ||
|
||
std::vector<std::string> vec; | ||
while (t.HasMore()) | ||
t.GetNext(vec.emplace_back()); | ||
|
||
EXPECT_EQ(vec.size(), 6); | ||
} | ||
|
||
{ | ||
StringTokenizer t("A Quick brown\nfox jumps\rover the fence"); | ||
|
||
std::vector<std::string> vec; | ||
while (t.HasMore()) | ||
t.GetNext(vec.emplace_back()); | ||
|
||
EXPECT_EQ(vec.size(), 8); | ||
} | ||
} | ||
} // namespace | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,2 @@ | ||
target("Console") | ||
set_kind("static") | ||
set_group("Components") | ||
add_configfiles("BuildInfo.h.in") | ||
add_includedirs( | ||
".", | ||
"../", | ||
"../../", | ||
"../../../build", | ||
{public = true}) | ||
add_headerfiles("**.h") | ||
add_files("**.cpp") | ||
add_packages( | ||
"tiltedcore", | ||
"hopscotch-map", | ||
"gtest", | ||
"spdlog") | ||
component("Console") | ||
unittest("Console") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,47 @@ | ||
-- List all components required here. | ||
-- This function defines the core component idoms | ||
function component(name) | ||
target(name) | ||
set_kind("static") | ||
set_group("Components") | ||
add_configfiles("BuildInfo.h.in") | ||
add_includedirs( | ||
".", | ||
"../", | ||
"../../", | ||
"../../../build", | ||
{public = true}) | ||
add_headerfiles("**.h") | ||
add_files("**.cpp") | ||
add_packages( | ||
"tiltedcore", | ||
"hopscotch-map", | ||
"gtest", | ||
"spdlog") | ||
end | ||
|
||
-- this isnt fully specified yet. | ||
function unittest(name) | ||
target(name .. "-Test") | ||
set_kind("binary") | ||
set_group("Components") | ||
add_configfiles("BuildInfo.h.in") | ||
add_includedirs( | ||
".", | ||
"../", | ||
"../../", | ||
"../../../build", | ||
{public = true}) | ||
add_headerfiles( | ||
"**.h") | ||
add_files( | ||
"**.cpp", | ||
"../../../build/TestMain.cpp") | ||
add_packages( | ||
"tiltedcore", | ||
"hopscotch-map", | ||
"gtest", | ||
"spdlog") | ||
end | ||
|
||
-- List all components required below: | ||
includes("console") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters