Skip to content

Commit

Permalink
Get the French string right
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Sep 1, 2023
1 parent e2f929d commit 7cf8d23
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions six/modules/c++/six.sicd/unittests/test_CollectionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@

#include "TestCase.h"

// It seems that a macro is better than a utility routine, see https://github.com/tahonermann/char8_t-remediation
// C++20 changed the type of u8 to char8_t* https://en.cppreference.com/w/cpp/language/string_literal
// Not putting this everywhere because (1) well, it's a macro, and (2) it's mostly
// only test code that uses string literals.
#if CODA_OSS_cpp20
#define U8(s) u8##s
#else
#define U8(s) static_cast<const std::char8_t*>(static_cast<const void*>(s))
#endif

static void test_DummyData_parameters(const std::string& testName, const six::ParameterCollection& parameters,
std::optional<bool> preserveCharacterData = std::optional<bool>())
{
Expand Down Expand Up @@ -135,8 +125,10 @@ TEST_CASE(ClassificationCanada)
{
#ifdef _WIN32
const std::string classificationText("NON CLASSIFI\xc9 / UNCLASSIFIED"); // ISO8859-1 "NON CLASSIFIÉ / UNCLASSIFIED"
const auto E_ = str::u8FromString("\xc9"); // ISO8859-1 "É"
#else
const std::string classificationText("NON CLASSIFI\xc3\x89 / UNCLASSIFIED"); // UTF-8 "NON CLASSIFIÉ / UNCLASSIFIED"
const auto E_ = str::u8FromString("\xc3\x89"); // UTF-8 "É"
#endif

auto data = createData<six::zfloat>(types::RowCol<size_t>(10, 10));
Expand All @@ -145,14 +137,14 @@ TEST_CASE(ClassificationCanada)

const auto strXml = six::sicd::Utilities::toXMLString(*data, nullptr /*pSchemaPaths*/);

const auto NON_CLASSIFI = strXml.find(U8("NON CLASSIFI"));
const auto NON_CLASSIFI = strXml.find(str::u8FromString("NON CLASSIFI"));
TEST_ASSERT(NON_CLASSIFI != std::string::npos);
const auto UNCLASSIFIED = strXml.find(U8(" / UNCLASSIFIED"));
const auto UNCLASSIFIED = strXml.find(str::u8FromString(" / UNCLASSIFIED"));
TEST_ASSERT(UNCLASSIFIED != std::string::npos);
const auto utf8 = strXml.substr(NON_CLASSIFI, UNCLASSIFIED - NON_CLASSIFI);
TEST_ASSERT_EQ(utf8.size(), std::string("NON CLASSIFI\xc3\x89").size()); // UTF-8, "NON CLASSIFIÉ"
const auto E_ = utf8.find(U8("\xc3\x89")); // UTF-8, "É"
TEST_ASSERT(E_ != std::string::npos);
const auto posE_ = utf8.find(E_);
TEST_ASSERT(posE_ != std::string::npos);

io::U8StringStream ss;
ss.stream() << strXml;
Expand Down

0 comments on commit 7cf8d23

Please sign in to comment.