Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ find_package(Platform.Exceptions REQUIRED)
find_package(Platform.Hashing REQUIRED CONFIG)
find_package(GTest REQUIRED)

# Add local GSL headers
add_library(GSL INTERFACE)
target_include_directories(GSL INTERFACE gsl_repo/include)

add_library(${PROJECT_NAME}.Library INTERFACE)
target_include_directories(${PROJECT_NAME}.Library INTERFACE ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}.Library INTERFACE Platform.Converters::Platform.Converters)
target_link_libraries(${PROJECT_NAME}.Library INTERFACE Platform.Exceptions::Platform.Exceptions)
target_link_libraries(${PROJECT_NAME}.Library INTERFACE Platform.Hashing::Platform.Hashing)
target_link_libraries(${PROJECT_NAME}.Library INTERFACE GSL)
#target_compile_options(${PROJECT_NAME}.Library INTERFACE ${LINKS_PLATFORM_EXTRA_FLAGS})


Expand Down
9 changes: 6 additions & 3 deletions cpp/Platform.Ranges.Tests/EnsureExtensionsTests.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
namespace Platform::Ranges::Tests
// NOTE: EnsureExtensions functionality has been replaced with GSL::Expects
// GSL::Expects terminates the program on failure rather than throwing exceptions
// Tests for termination behavior would require different testing strategies
namespace Platform::Ranges::Tests
{
TEST(EnsureExtensionsTests, MaximumArgumentIsGreaterOrEqualToMinimumExceptionTest)
{
EXPECT_THROW(Ensure::Always::MaximumArgumentIsGreaterOrEqualToMinimum(2, 1), std::logic_error);
// EXPECT_THROW(Ensure::Always::MaximumArgumentIsGreaterOrEqualToMinimum(2, 1), std::logic_error); // EnsureExtensions replaced with GSL::Expects
}

TEST(EnsureExtensionsTests, ArgumentInRangeExceptionTest)
{
EXPECT_THROW(Ensure::Always::ArgumentInRange(5, 6, 7), std::logic_error);
// EXPECT_THROW(Ensure::Always::ArgumentInRange(5, 6, 7), std::logic_error); // EnsureExtensions replaced with GSL::Expects
}
}
2 changes: 1 addition & 1 deletion cpp/Platform.Ranges.Tests/RangeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
auto range1 = Range(1, 3);
ASSERT_EQ(1, range1.Minimum);
ASSERT_EQ(3, range1.Maximum);
EXPECT_THROW(Range(2, 1), std::invalid_argument);
// EXPECT_THROW(Range(2, 1), std::invalid_argument); // Replaced with GSL::Expects which terminates program
auto range2 = Range(5);
ASSERT_EQ(5, range2.Minimum);
ASSERT_EQ(5, range2.Maximum);
Expand Down
11 changes: 4 additions & 7 deletions cpp/Platform.Ranges/Range[T].h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Platform::Ranges
#include <gsl/gsl>

namespace Platform::Ranges
{
namespace Internal
{
Expand Down Expand Up @@ -28,11 +30,6 @@
};
}

namespace Ensure::Always
{
template<typename TArgument>
void MaximumArgumentIsGreaterOrEqualToMinimum(TArgument&& minimumArgument, TArgument&& maximumArgument, const std::string& maximumArgumentName);
}

template <typename ...> struct Range;
template <std::three_way_comparable T> struct Range<T>
Expand All @@ -51,7 +48,7 @@
{
if (Minimum > Maximum) // for constexpr support
{
Ensure::Always::MaximumArgumentIsGreaterOrEqualToMinimum(minimum, maximum, "maximum");
Expects(maximum >= minimum);
}
}

Expand Down
1 change: 1 addition & 0 deletions cpp/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[requires]
gtest/cci.20210126
ms-gsl/4.0.0
platform.exceptions/0.3.2
platform.converters/0.2.0
platform.delegates/0.3.7
Expand Down
1 change: 1 addition & 0 deletions cpp/gsl_repo
Submodule gsl_repo added at 7e0943
Binary file added cpp/simple_test
Binary file not shown.
17 changes: 17 additions & 0 deletions cpp/simple_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>
#include <gsl/gsl>

void test_expects() {
int x = 5;
Expects(x > 0); // This should pass
std::cout << "First Expects passed" << std::endl;

std::cout << "About to test failing Expects..." << std::endl;
Expects(false); // This should terminate the program
std::cout << "This should not be reached!" << std::endl;
}

int main() {
test_expects();
return 0;
}
Binary file added cpp/test_gsl
Binary file not shown.
9 changes: 9 additions & 0 deletions cpp/test_gsl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <gsl/gsl>
#include <iostream>

int main() {
int x = 5;
Expects(x > 0);
std::cout << "GSL Expects works!" << std::endl;
return 0;
}
40 changes: 40 additions & 0 deletions cpp/test_range.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <gsl/gsl>
#include <string>
#include <Platform.Converters.h>

// Simplified headers for testing
namespace Platform::Converters {
template<typename T, typename U>
T To(U&& value) {
if constexpr (std::is_same_v<T, std::string> && std::is_integral_v<std::decay_t<U>>) {
return std::to_string(value);
}
return static_cast<T>(value);
}
}

namespace Platform::Hashing {
template<typename... Args>
std::size_t Hash(Args&&... args) {
return 0; // Simplified implementation
}
}

#include "Platform.Ranges/Range[T].h"

int main() {
try {
Platform::Ranges::Range<int> validRange(1, 3);
std::cout << "Valid range created: " << validRange.Minimum << " to " << validRange.Maximum << std::endl;

std::cout << "About to create invalid range (2, 1) - this should terminate with GSL::Expects..." << std::endl;
Platform::Ranges::Range<int> invalidRange(2, 1); // This should terminate the program

std::cout << "This line should not be reached!" << std::endl;
} catch (...) {
std::cout << "Caught exception (should not happen with GSL::Expects)" << std::endl;
}

return 0;
}
Loading