an example of using constexpr array for data

simplifies code and removes the need for a class.
This commit is contained in:
berniev
2023-02-23 03:34:30 +10:00
committed by wwmayer
parent 5e77365c0d
commit 0a5e59adae
8 changed files with 132 additions and 280 deletions

View File

@@ -2,83 +2,32 @@
#include "App/License.h"
TEST(License, AllRightsReserved)
TEST(License, isLicenseYesStr)
{
auto lic = App::License{App::License::Type::AllRightsReserved};
ASSERT_EQ(lic.getType(), App::License::Type::AllRightsReserved);
ASSERT_EQ(lic.getLicense(), "All rights reserved");
ASSERT_EQ(lic.getUrl(), "https://en.wikipedia.org/wiki/All_rights_reserved");
EXPECT_EQ(App::findLicense("CC_BY_40"), 1);
}
TEST(License, CC_BY_40)
TEST(License, UnknownIdentifier)
{
auto lic = App::License{App::License::Type::CC_BY_40};
ASSERT_EQ(lic.getType(), App::License::Type::CC_BY_40);
ASSERT_EQ(lic.getLicense(), "Creative Commons Attribution");
ASSERT_EQ(lic.getUrl(), "https://creativecommons.org/licenses/by/4.0/");
int index {App::findLicense("junk")};
EXPECT_EQ(index, -1);
}
TEST(License, CC_BY_SA_40)
TEST(License, direct)
{
auto lic = App::License{App::License::Type::CC_BY_SA_40};
ASSERT_EQ(lic.getType(), App::License::Type::CC_BY_SA_40);
ASSERT_EQ(lic.getLicense(), "Creative Commons Attribution-ShareAlike");
ASSERT_EQ(lic.getUrl(), "https://creativecommons.org/licenses/by-sa/4.0/");
int posn {App::findLicense("CC_BY_40")};
App::TLicenseArr tt {
"CC_BY_40", "Creative Commons Attribution", "https://creativecommons.org/licenses/by/4.0/"};
EXPECT_EQ(App::licenseItems.at(posn), tt);
}
TEST(License, PublicDomain)
TEST(License, findLicenseByIdent)
{
auto lic = App::License{App::License::Type::PublicDomain};
ASSERT_EQ(lic.getType(), App::License::Type::PublicDomain);
ASSERT_EQ(lic.getLicense(), "Public Domain");
ASSERT_EQ(lic.getUrl(), "https://en.wikipedia.org/wiki/Public_domain");
App::TLicenseArr arr {App::licenseItems.at(App::findLicense("CC_BY_40"))};
EXPECT_STREQ(arr.at(App::posnOfIdentifier), "CC_BY_40");
EXPECT_STREQ(arr.at(App::posnOfFullName), "Creative Commons Attribution");
EXPECT_STREQ(arr.at(App::posnOfUrl), "https://creativecommons.org/licenses/by/4.0/");
}
TEST(License, FreeArt)
{
auto lic = App::License{App::License::Type::FreeArt};
ASSERT_EQ(lic.getType(), App::License::Type::FreeArt);
ASSERT_EQ(lic.getLicense(), "FreeArt");
ASSERT_EQ(lic.getUrl(), "https://artlibre.org/licence/lal");
}
TEST(License, CERN_OHS_S)
{
auto lic = App::License{App::License::Type::CERN_OHS_S};
ASSERT_EQ(lic.getType(), App::License::Type::CERN_OHS_S);
ASSERT_EQ(lic.getLicense(), "CERN Open Hardware Licence strongly-reciprocal");
ASSERT_EQ(lic.getUrl(), "https://cern-ohl.web.cern.ch/");
}
TEST(License, Other)
{
auto lic = App::License{App::License::Type::Other};
ASSERT_EQ(lic.getType(), App::License::Type::Other);
ASSERT_EQ(lic.getLicense(), "Other");
ASSERT_EQ(lic.getUrl(), "");
}
TEST(License, CompareTypeWithInt)
{
auto lic1 = App::License{App::License::Type::Other};
auto lic2 = App::License{static_cast<int>(App::License::Type::Other)};
ASSERT_EQ(lic1.getType(), lic2.getType());
}
TEST(License, CompareTypeWithLong)
{
auto lic1 = App::License{App::License::Type::CC_BY_NC_ND_40};
auto lic2 = App::License{static_cast<long>(App::License::Type::CC_BY_NC_ND_40)};
ASSERT_EQ(lic1.getType(), lic2.getType());
}
TEST(License, All)
{
std::vector<std::string> all = App::License::getLicenses();
int num = static_cast<int>(all.size());
for (int index = 0; index < num; index++) {
auto lic = App::License{index};
auto text = all.at(index);
ASSERT_EQ(lic.getLicense(), text);
}
}