Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test with windows.h header and remedy conflicts #345

Merged
merged 7 commits into from
Oct 18, 2024
Merged
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
8 changes: 4 additions & 4 deletions converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include "CLI11.hpp"
#include "units/units.hpp"
#include <cstdio>
#include <string>

int main(int argc, char* argv[])
{
Expand Down Expand Up @@ -42,10 +43,9 @@ int main(int argc, char* argv[])
newUnits,
"the units to convert the measurement to, '*' to convert to base units")
->required();
app.add_flag_callback("--version,-v", []() {
std::cout << "Units conversion " UNITS_VERSION_STRING << '\n';
throw CLI::Success();
});
app.set_version_flag(
"--version,-v", "Units conversion " UNITS_VERSION_STRING);

app.positionals_at_end();

CLI11_PARSE(app, argc, argv);
Expand Down
17 changes: 16 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,26 @@ else()
endif()

add_executable(examples_test examples_test.cpp)
target_link_libraries(examples_test PRIVATE ${UNITS_LC_PROJECT_NAME}::units)
target_link_libraries(
examples_test PRIVATE ${UNITS_LC_PROJECT_NAME}::units compile_flags_target
)
target_compile_definitions(examples_test PRIVATE ${TARGET_SPECIAL_COMPILER_FLAGS})
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
compile_flags_target
)
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 "units/units_decl.hpp"
#include <Windows.h>

#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;
}
2 changes: 2 additions & 0 deletions test/fuzz_issue_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ SPDX-License-Identifier: BSD-3-Clause
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

using namespace units;
TEST(fuzzFailures, convFailures)
Expand Down
1 change: 1 addition & 0 deletions test/test_all_unit_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include "test.hpp"
#include "units/units.hpp"

#include <iostream>
#include <limits>
using namespace units;

Expand Down
2 changes: 2 additions & 0 deletions test/test_complete_unit_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ SPDX-License-Identifier: BSD-3-Clause

#include <cmath>
#include <fstream>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>

static std::string hexConvert(const std::string& str)
{
Expand Down
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
1 change: 1 addition & 0 deletions test/test_conversions2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-3-Clause

#include <algorithm>
#include <fstream>
#include <string>
#include <vector>

// structure containing information on a single conversion
Expand Down
1 change: 1 addition & 0 deletions test/test_defined_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include "test.hpp"
#include "units/units_conversion_maps.hpp"
#include <map>
#include <string>
#include <unordered_map>

TEST(unitStringDefinitions, siVectorLength)
Expand Down
2 changes: 2 additions & 0 deletions test/test_equation_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ SPDX-License-Identifier: BSD-3-Clause
#include "test.hpp"
#include "units/units.hpp"

#include <vector>

using namespace units;

TEST(logUnits, nonEquality)
Expand Down
2 changes: 2 additions & 0 deletions test/test_google_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ SPDX-License-Identifier: BSD-3-Clause

#include <cmath>
#include <fstream>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>

TEST(googleUnits, unitTypes)
{
Expand Down
2 changes: 2 additions & 0 deletions test/test_leadingNumbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ SPDX-License-Identifier: BSD-3-Clause
#include "units/units.hpp"

#include <cmath>
#include <string>
#include <vector>

using namespace units::detail::testing;

Expand Down
2 changes: 2 additions & 0 deletions test/test_measurement_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ SPDX-License-Identifier: BSD-3-Clause
#include "units/units.hpp"

#include <iostream>
#include <string>
#include <type_traits>
#include <vector>

using namespace units;
TEST(MeasurementStrings, basic)
Expand Down
2 changes: 2 additions & 0 deletions test/test_r20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ SPDX-License-Identifier: BSD-3-Clause
#include "test.hpp"
#include "units/units.hpp"

#include <iostream>
#include <string>
#include <tuple>

using unitD = std::tuple<const char*, const char*, units::precise_unit>;
Expand Down
1 change: 1 addition & 0 deletions test/test_random_round_trip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include <chrono>
#include <limits>
#include <random>
#include <vector>

using namespace units;

Expand Down
3 changes: 3 additions & 0 deletions test/test_siunits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ SPDX-License-Identifier: BSD-3-Clause
#include <fstream>
#include <ostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

static std::vector<std::vector<std::string>>
loadCsvFile(const std::string& file)
Expand Down
3 changes: 3 additions & 0 deletions test/test_ucum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ SPDX-License-Identifier: BSD-3-Clause

#include <cmath>
#include <fstream>
#include <iostream>
#include <json.hpp>
#include <ostream>
#include <set>
#include <sstream>
#include <string>

TEST(UCUM, domain_exclusion)
{
Expand Down
2 changes: 2 additions & 0 deletions test/test_udunits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ SPDX-License-Identifier: BSD-3-Clause

#include <cmath>
#include <fstream>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>

TEST(UDUNITS, acceptedNameSymbols)
{
Expand Down
1 change: 1 addition & 0 deletions test/test_uncertain_measurements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include "units/units.hpp"

#include <memory>
#include <string>

using namespace units;
TEST(uncertainOps, construction)
Expand Down
1 change: 1 addition & 0 deletions test/test_unit_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SPDX-License-Identifier: BSD-3-Clause
#include "units/units_decl.hpp"
#include "units/units_util.hpp"

#include <limits>
#include <memory>

using namespace units;
Expand Down
11 changes: 7 additions & 4 deletions test/test_unit_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ SPDX-License-Identifier: BSD-3-Clause

#include "test.hpp"
#include <algorithm>
#include <limits>
#include <string>
#include <vector>

#if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703)
#ifndef UNITS_CONSTEXPR_IF_SUPPORTED
Expand Down Expand Up @@ -1513,7 +1516,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 +1532,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 +1547,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
Loading