2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright (C) 2013-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2020-08-11 18:11:55 +00:00
|
|
|
|
|
|
|
#include "transmission.h"
|
|
|
|
#include "quark.h"
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
2021-10-15 13:28:47 +00:00
|
|
|
#include <string_view>
|
2020-08-11 18:11:55 +00:00
|
|
|
|
|
|
|
class QuarkTest : public ::testing::Test
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
template<typename T>
|
|
|
|
std::string quarkGetString(T i)
|
|
|
|
{
|
2022-08-28 21:17:07 +00:00
|
|
|
return std::string{ tr_quark_get_string_view(tr_quark(i)) };
|
2020-08-11 18:11:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(QuarkTest, allPredefinedKeysCanBeLookedUp)
|
|
|
|
{
|
2022-03-28 02:55:30 +00:00
|
|
|
for (size_t i = 0; i < TR_N_KEYS; ++i)
|
2020-08-11 18:11:55 +00:00
|
|
|
{
|
|
|
|
auto const str = quarkGetString(i);
|
2021-11-01 23:29:13 +00:00
|
|
|
auto const q = tr_quark_lookup(str);
|
|
|
|
EXPECT_TRUE(q);
|
|
|
|
EXPECT_EQ(i, *q);
|
2020-08-11 18:11:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-15 13:28:47 +00:00
|
|
|
TEST_F(QuarkTest, newQuarkByStringView)
|
2020-08-11 18:11:55 +00:00
|
|
|
{
|
2021-10-15 13:28:47 +00:00
|
|
|
auto constexpr UniqueString = std::string_view{ "this string is not a predefined quark" };
|
|
|
|
auto const q = tr_quark_new(UniqueString);
|
2022-08-28 21:17:07 +00:00
|
|
|
EXPECT_EQ(UniqueString, tr_quark_get_string_view(q));
|
2020-08-11 18:11:55 +00:00
|
|
|
}
|