Skip to content

Commit

Permalink
test with windows.h header and remedy conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Oct 17, 2024
1 parent 33a4bf9 commit 14df57f
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 151 deletions.
8 changes: 8 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ else()
set_target_properties(examples_test PROPERTIES FOLDER "Tests")
add_test(examples_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples_test)

if (WIN32)
add_executable(examples_test_windows examples_test_windows.cpp)
target_link_libraries(examples_test_windows PRIVATE ${UNITS_LC_PROJECT_NAME}::units)
target_compile_definitions(examples_test_windows PRIVATE ${TARGET_SPECIAL_COMPILER_FLAGS})
set_target_properties(examples_test_windows PROPERTIES FOLDER "Tests")
add_test(examples_test_windows ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples_test)
endif()

add_executable(test_all_unit_base test_all_unit_base.cpp)
if(MSVC)
target_compile_options(test_all_unit_base PRIVATE /wd4459)
Expand Down
58 changes: 58 additions & 0 deletions test/examples_test_windows.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright (c) 2019-2023,
Lawrence Livermore National Security, LLC;
See the top-level NOTICE for additional details. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
*/
#include <Windows.h>
#include "units/units_decl.hpp"

#include "units/units.hpp"
#include "units/units_conversion_maps.hpp"

/** @file Test just to load up some unit definitions and do some operations with
them it tests linking and some usefulness in code coverage */

int main(int argc, char* argv[])
{
units::fixed_precise_measurement fpm1(1250.0, units::precise::cm.pow(3));
units::fixed_precise_measurement fpm2(1.25, units::precise::L);
if (fpm1 != fpm2) {
return -1;
}

units::uncertain_measurement um1(1250.0, 25.0, units::cm.pow(3));
units::uncertain_measurement um2(1.25, 0.1, units::L);
if (um1 != um2) {
return -1;
}

units::measurement m1(1250.0, units::cm.pow(3));
if (m1 != 1.25 * units::L) {
return -1;
}

units::fixed_measurement fm1(1250.0, units::cm.pow(3));
if (fm1 != 1.25 * units::L) {
return -1;
}

units::precise_measurement pm1 =
units::measurement_from_string("1250 cm^3");
if (pm1 != 1.25 * units::precise::L) {
return -1;
}

units::precise_unit prec1(1.25, units::precise::L);

if (prec1 != units::precise_unit(0.00125, units::precise::m.pow(3))) {
return -1;
}

units::unit u1(1.25, units::L);

if (u1 != units::unit(0.00125, units::m.pow(3))) {
return -1;
}
return 0;
}
8 changes: 4 additions & 4 deletions test/test_conversions1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ TEST(TimeConversions, Correctness)
double one_week_in_day = 7.0;
double one_day_in_sec = 86400.0;

EXPECT_NEAR(convert(min, s), one_min_in_sec, test::tolerance);
EXPECT_NEAR(convert(hr, min), one_hour_in_min, test::tolerance);
EXPECT_NEAR(convert(minute, s), one_min_in_sec, test::tolerance);
EXPECT_NEAR(convert(hr, minute), one_hour_in_min, test::tolerance);
EXPECT_NEAR(
convert(unit_cast(precise::time::day), hr),
one_day_in_hour,
Expand Down Expand Up @@ -421,10 +421,10 @@ TEST(TimeConversionsPrecise, Correctness)
double one_day_in_sec = 86400.0;

EXPECT_NEAR(
convert(min, units::precise::s),
convert(minute, units::precise::s),
one_min_in_sec,
test::precise_tolerance);
EXPECT_NEAR(convert(hr, min), one_hour_in_min, test::precise_tolerance);
EXPECT_NEAR(convert(hr, minute), one_hour_in_min, test::precise_tolerance);
EXPECT_NEAR(convert(day, hr), one_day_in_hour, test::precise_tolerance);
EXPECT_NEAR(convert(week, day), one_week_in_day, test::precise_tolerance);
EXPECT_NEAR(
Expand Down
8 changes: 4 additions & 4 deletions test/test_unit_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ TEST(userDefinedUnits, definitionStrings)
addUserDefinedUnit("idgit", idgit);

auto ipm = unit_from_string("idgit/min");
EXPECT_EQ(ipm, idgit / min);
EXPECT_EQ(ipm, idgit / minute);

auto str = to_string(ipm);
EXPECT_EQ(str, "idgit/min");
Expand All @@ -1529,7 +1529,7 @@ TEST(userDefinedUnits, definitionStringsInputOnly)
addUserDefinedInputUnit("idgit", idgit);

auto ipm = unit_from_string("idgit/min");
EXPECT_EQ(ipm, idgit / min);
EXPECT_EQ(ipm, idgit / minute);

auto str = to_string(ipm);
/** input only should not result in any string result with the user defined
Expand All @@ -1544,9 +1544,9 @@ TEST(userDefinedUnits, definitionStringsOutputOnly)
addUserDefinedOutputUnit("idgit", idgit);

auto ipm = unit_from_string("idgit/min");
EXPECT_NE(ipm, idgit / min);
EXPECT_NE(ipm, idgit / minute);

auto str = to_string(idgit / min);
auto str = to_string(idgit / minute);
/** output only should make this work*/
EXPECT_EQ(str, "idgit/min");
clearUserDefinedUnits();
Expand Down
Loading

0 comments on commit 14df57f

Please sign in to comment.