Skip to content

Commit

Permalink
latest from coda-oss
Browse files Browse the repository at this point in the history
  • Loading branch information
JDanielSmith committed Jun 24, 2022
1 parent 04410ed commit 4f2dfc0
Show file tree
Hide file tree
Showing 142 changed files with 3,148 additions and 1,551 deletions.
62 changes: 34 additions & 28 deletions externals/coda-oss/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
```
_________________________
| ____ _||_ ___ __ |
| /___ \/_||_\| __\/ \ |
| // \// || \|| \\ _ \ |
| || [===||===] ||(_)| |
| || _|| || ||| ||__ | |
| \\ _/ |\_||_/||__/|| || |
| \___/ \_||_/|___/|| || |
|__________||_____________|
```
# coda-oss Release Notes

## Release 2022-05-03
* Fixed a bug in `Poly2D::atY()`; imporved `flipXY()` behavior.
* Implement [std::filesystem::file_size()](https://en.cppreference.com/w/cpp/filesystem/file_size).
```
_________________________
| ____ _||_ ___ __ |
| /___ \/_||_\| __\/ \ |
| // \// || \|| \\ _ \ |
| || [===||===] ||(_)| |
| || _|| || ||| ||__ | |
| \\ _/ |\_||_/||__/|| || |
| \___/ \_||_/|___/|| || |
|__________||_____________|
```
# coda-oss Release Notes

## Release 2022-??-??
* Build most code in Visual Studio 2022
* Removed more compiler warnings
* Begin work on `CODA_OSS_API` (needed for building a shared-library/DLL)
* Add `run1D()` method to `mt::GenerationThreadPool`

## Release 2022-05-03
* Fixed a bug in `Poly2D::atY()`; improved `flipXY()` behavior.
* Implement [std::filesystem::file_size()](https://en.cppreference.com/w/cpp/filesystem/file_size).
* use `inline` functions for `TEST_` macros
* force use of [64-bit `time_t`](https://en.wikipedia.org/wiki/Year_2038_problem)
* more routines now support a `std::span` overload; e.g., `io::InputStream::read()`.

## (Release 2022-02-22)
* new `EnocdedString` and `EncodedStringView` to manage strings in different encodings
* XML containing UTF-8 characters can now be validated
* Update to [GSL 4.0.0](https://github.com/microsoft/GSL/releases/tag/v4.0.0)
* our implementation of `std` stuff is all in the `coda_oss` namespace
* old, unused **log4j.jar** deleted to remove any questions about the security vulnerability

## [Release 2021-12-13](https://github.com/mdaus/coda-oss/releases/tag/2021-12-13)
* Try hard to parse XML encoded in various ways
* Simplify XML element creation for common idioms
* more routines now support a `std::span` overload; e.g., `io::InputStream::read()`.

## (Release 2022-02-22)
* new `EnocdedString` and `EncodedStringView` to manage strings in different encodings
* XML containing UTF-8 characters can now be validated
* Update to [GSL 4.0.0](https://github.com/microsoft/GSL/releases/tag/v4.0.0)
* our implementation of `std` stuff is all in the `coda_oss` namespace
* old, unused **log4j.jar** deleted to remove any questions about the security vulnerability

## [Release 2021-12-13](https://github.com/mdaus/coda-oss/releases/tag/2021-12-13)
* Try hard to parse XML encoded in various ways
* Simplify XML element creation for common idioms
43 changes: 43 additions & 0 deletions externals/coda-oss/UnitTest/CppUnitTestAssert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "pch.h"
#include "TestCase.h"

#include "str/EncodedStringView.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

// EQUALS_MESSAGE() wants ToString() specializations (or overloads) for our types, which is a nusiance.
// This hooks up our existing str::toString() into the VC++ unit-test infrastructure

// C++ hack to call private methods
// https://stackoverflow.com/questions/6873138/calling-private-method-in-c?msclkid=dd8b1f8bd09711ec8610b4501a04de94

using FailOnCondition_t = void(bool condition, const unsigned short* message, const __LineInfo* pLineInfo); // declare method's type
using GetAssertMessage_t = std::wstring(bool equality, const std::wstring& expected, const std::wstring& actual, const wchar_t *message); // declare method's type
template <FailOnCondition_t fFailOnCondition, GetAssertMessage_t fGetAssertMessage>
struct caller final // helper structure to inject call() code
{
friend void FailOnCondition(bool condition, const unsigned short* message, const __LineInfo* pLineInfo)
{
fFailOnCondition(condition, message, pLineInfo);
}

friend std::wstring GetAssertMessage(bool equality, const std::wstring& expected, const std::wstring& actual, const wchar_t *message)
{
return fGetAssertMessage(equality, expected, actual, message);
}
};
template struct caller<&Assert::FailOnCondition, &Assert::GetAssertMessage>; // even instantiation of the helper

void FailOnCondition(bool condition, const unsigned short* message, const __LineInfo* pLineInfo); // declare caller
void test::Assert::FailOnCondition(bool condition, const unsigned short* message, const __LineInfo* pLineInfo)
{
::FailOnCondition(condition, message, pLineInfo); // and call!
}

std::wstring GetAssertMessage(bool equality, const std::wstring& expected, const std::wstring& actual, const wchar_t *message); // declare caller
std::wstring test::Assert::GetAssertMessage(bool equality, const std::string& expected, const std::string& actual, const wchar_t *message)
{
const str::EncodedStringView vExpected(expected);
const str::EncodedStringView vActual(actual);
return ::GetAssertMessage(equality, vExpected.wstring(), vActual.wstring(), message); // and call!
}
137 changes: 137 additions & 0 deletions externals/coda-oss/UnitTest/TestCase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#pragma once

#include <stdint.h>
#include <string>

#include "CppUnitTest.h"
#include <include/TestCase.h>
#include <str/EncodedStringView.h>

#undef TEST_CHECK
#undef TEST_ASSERT
#undef TEST_ASSERT_NULL
#undef TEST_ASSERT_TRUE
#undef TEST_ASSERT_FALSE
#undef TEST_MAIN
#undef TEST_CASE
#define TEST_CHECK(X)
#define TEST_MAIN(X)
#define TEST_ASSERT_NULL(X) testName, Microsoft::VisualStudio::CppUnitTestFramework::Assert::IsNull((X))
#define TEST_ASSERT_TRUE(X) testName, Microsoft::VisualStudio::CppUnitTestFramework::Assert::IsTrue((X))
#define TEST_ASSERT_FALSE(X) testName, Microsoft::VisualStudio::CppUnitTestFramework::Assert::IsFalse((X))
#define TEST_ASSERT(X) TEST_ASSERT_TRUE(X)
#define CODA_OSS_testMethod_(X) testMethod ## _ ## X
#define TEST_CASE(X) TEST_METHOD(X) { CODA_OSS_testMethod_(X)(#X); } void CODA_OSS_testMethod_(X)(std::string testName)

namespace test
{
struct Assert final
{
static void FailOnCondition(bool condition, const unsigned short* message, const Microsoft::VisualStudio::CppUnitTestFramework::__LineInfo* pLineInfo);
static std::wstring GetAssertMessage(bool equality, const std::string& expected, const std::string& actual, const wchar_t *message);
};
#define CODA_OSS_equals_message_(expected, actual, message) reinterpret_cast<const unsigned short*>(test::Assert::GetAssertMessage(true, str::toString(expected), str::toString(actual), message).c_str())
#define CODA_OSS_not_equals_message_(notExpected, actual, message) reinterpret_cast<const unsigned short*>(test::Assert::GetAssertMessage(false, str::toString(notExpected), str::toString(actual), message).c_str())
#define CODA_OSS_message_(message) reinterpret_cast<const unsigned short*>(test::Assert::GetAssertMessage(false, "", "", message).c_str())

// see Assert::AreEqual<>
template<typename TExpected, typename TActual>
inline void diePrintf_eq(const TExpected& expected, const TActual& actual,
const wchar_t* message = NULL, const Microsoft::VisualStudio::CppUnitTestFramework::__LineInfo* pLineInfo = NULL)
{
Assert::FailOnCondition(expected == actual, CODA_OSS_equals_message_(expected, actual, message), pLineInfo);
}

// see Assert::AreNotEqual<>
template<typename TExpected, typename TActual>
inline void diePrintf_ne(const TExpected& notExpected, const TActual& actual,
const wchar_t* message = NULL, const Microsoft::VisualStudio::CppUnitTestFramework::__LineInfo* pLineInfo = NULL)
{
Assert::FailOnCondition(notExpected != actual, CODA_OSS_not_equals_message_(notExpected, actual, message), pLineInfo);
}

template <typename TX1, typename TX2>
inline void diePrintf_ge(const TX1& X1, const TX2& X2,
const wchar_t* message = NULL, const Microsoft::VisualStudio::CppUnitTestFramework::__LineInfo* pLineInfo = NULL)
{
Assert::FailOnCondition(X1 >= X2, CODA_OSS_message_(message), pLineInfo);
}
template <typename TX1, typename TX2>
inline void diePrintf_gt(const TX1& X1, const TX2& X2,
const wchar_t* message = NULL, const Microsoft::VisualStudio::CppUnitTestFramework::__LineInfo* pLineInfo = NULL)
{
Assert::FailOnCondition(X1 > X2, CODA_OSS_message_(message), pLineInfo);
}
template <typename TX1, typename TX2>
inline void diePrintf_le(const TX1& X1, const TX2& X2,
const wchar_t* message = NULL, const Microsoft::VisualStudio::CppUnitTestFramework::__LineInfo* pLineInfo = NULL)
{
Assert::FailOnCondition(X1 <= X2, CODA_OSS_message_(message), pLineInfo);
}
template <typename TX1, typename TX2>
inline void diePrintf_lt(const TX1& X1, const TX2& X2,
const wchar_t* message = NULL, const Microsoft::VisualStudio::CppUnitTestFramework::__LineInfo* pLineInfo = NULL)
{
Assert::FailOnCondition(X1 < X2, CODA_OSS_message_(message), pLineInfo);
}

}
#undef CODA_OSS_test_diePrintf_eq_
#undef CODA_OSS_test_diePrintf_not_eq_
#define CODA_OSS_test_diePrintf_eq_(X1, X2) testName, test::diePrintf_eq(X1, X2)
#define CODA_OSS_test_diePrintf_not_eq_(X1, X2) testName, test::diePrintf_ne(X1, X2)

#undef CODA_OSS_test_diePrintf_greater_eq_
#undef CODA_OSS_test_diePrintf_greater_
#undef CODA_OSS_test_diePrintf_lesser_eq_
#undef CODA_OSS_test_diePrintf_lesser_
#define CODA_OSS_test_diePrintf_greater_eq_(X1, X2) testName, test::diePrintf_ge(X1, X2)
#define CODA_OSS_test_diePrintf_greater_(X1, X2) testName, test::diePrintf_gt(X1, X2)
#define CODA_OSS_test_diePrintf_lesser_eq_(X1, X2) testName, test::diePrintf_le(X1, X2)
#define CODA_OSS_test_diePrintf_lesser_(X1, X2) testName, test::diePrintf_lt(X1, X2)

template <typename TX1, typename TX2>
inline void test_assert_greater_(const TX1& X1, const TX2& X2)
{
Microsoft::VisualStudio::CppUnitTestFramework::Assert::IsTrue(X1 > X2);
}
#undef TEST_ASSERT_GREATER
#define TEST_ASSERT_GREATER(X1, X2) testName, test_assert_greater_(X1, X2)

#undef TEST_ASSERT_ALMOST_EQ_EPS
#define TEST_ASSERT_ALMOST_EQ_EPS(X1, X2, EPS) { (void)testName; Microsoft::VisualStudio::CppUnitTestFramework::Assert::AreEqual(X1, X2, EPS); Microsoft::VisualStudio::CppUnitTestFramework::Assert::AreEqual(X2, X1, EPS); }
namespace test
{
inline void assert_almost_eq(const std::string& testName, float X1, float X2)
{
constexpr auto EPS = static_cast<float>(0.0001);
TEST_ASSERT_ALMOST_EQ_EPS(X1, X2, EPS);
}
inline void assert_almost_eq(const std::string& testName, double X1, double X2)
{
constexpr auto EPS = static_cast<double>(0.0001);
TEST_ASSERT_ALMOST_EQ_EPS(X1, X2, EPS);
}
inline void assert_almost_eq(const std::string& testName, long double X1, long double X2)
{
assert_almost_eq(testName, static_cast<double>(X1), static_cast<double>(X2));
}
}

#undef TEST_ASSERT_ALMOST_EQ
#define TEST_ASSERT_ALMOST_EQ(X1, X2) test::assert_almost_eq(testName, X1, X2)

#undef TEST_ASSERT_EQ_MSG
#define TEST_ASSERT_EQ_MSG(msg, X1, X2) testName, Microsoft::VisualStudio::CppUnitTestFramework::Logger::WriteMessage(msg.c_str()); TEST_ASSERT_EQ(X1, X2)

#undef TEST_FAIL
#define TEST_FAIL(msg) { (void)testName; const str::EncodedStringView vw(msg); Microsoft::VisualStudio::CppUnitTestFramework::Assert::Fail(vw.wstring().c_str()); }

#undef TEST_EXCEPTION
#undef TEST_THROWS
#undef TEST_SPECIFIC_EXCEPTION
#define TEST_EXCEPTION(X) (void)testName; try{ (X); TEST_FAIL(#X " should have thrown."); } \
catch (const except::Throwable&){ TEST_ASSERT_TRUE(true); } catch (const except::Throwable11&){ TEST_ASSERT_TRUE(true); }
#define TEST_THROWS(X) (void)testName; try{ (X); TEST_FAIL(#X " should have thrown."); } catch (...){ TEST_ASSERT_TRUE(true); }
#define TEST_SPECIFIC_EXCEPTION(X, Y) testName, Microsoft::VisualStudio::CppUnitTestFramework::Assert::ExpectException<Y>([&](){(X);})

Loading

0 comments on commit 4f2dfc0

Please sign in to comment.