diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index dfb4b73..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Build and test - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Release - -jobs: - build: - name: ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [windows-2019, macos-10.15, ubuntu-latest] - #arch: [x86, x64] - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - - name: Build - # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - - name: Test - working-directory: ${{github.workspace}}/build - run: ctest -C RELEASE -V \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b00897e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: CI + +on: + push: + branches: [ '**' ] + pull_request: + branches: [ '**' ] + +jobs: + build-and-test: + name: ${{ matrix.os }} Build and Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + # For more specific OS versions, you can specify them explicitly: + # os: [ubuntu-20.04, windows-2019, macos-11] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up CMake + uses: jwlawson/actions-setup-cmake@v1 + with: + cmake-version: "3.20.0" # Specify the minimum version you need + + - name: Install dependencies (Windows) + if: runner.os == 'Windows' + run: | + choco install -y ninja + choco install -y llvm # Clang on Windows if needed + # choco install -y visualstudio2019community + shell: pwsh + + - name: Install dependencies (Ubuntu) + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y ninja-build clang + - name: Install dependencies (macOS) + if: runner.os == 'macOS' + run: | + brew update + brew install ninja + brew install llvm + + - name: Configure CMake + run: | + cmake -S . -B build -G Ninja -DCMAKE_CXX_COMPILER=clang++ + # Or specify other options as needed + - name: Build + run: cmake --build build + + - name: Run tests + run: ctest --test-dir build --output-on-failure \ No newline at end of file diff --git a/CMakeLists-xmlParser.txt b/CMakeLists-xmlParser.txt deleted file mode 100644 index 7f09c93..0000000 --- a/CMakeLists-xmlParser.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required( VERSION 2.8.7 ) - -# Create include directories that will connect to library itself. This must be created before downloading -# xmlParser library or otherwise connections will not be created - -set(xmlParser_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/xmlParser-src/include") - -include_directories(${xmlParser_INCLUDE_DIRS}) - -# Download and create Windows Calculation Engine library -configure_file(CMakeLists-xmlParser.txt.in ${CMAKE_BINARY_DIR}/xmlParser-download/CMakeLists.txt) -execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/xmlParser-download) -execute_process(COMMAND ${CMAKE_COMMAND} --build . - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/xmlParser-download) - -add_subdirectory(${CMAKE_BINARY_DIR}/xmlParser-src "${CMAKE_CURRENT_BINARY_DIR}/xmlParser-src") -set(xmlParser_LIB "${CMAKE_SHARED_LIBRARY_PREFIX}xmlParser${CMAKE_SHARED_LIBRARY_SUFFIX}") diff --git a/CMakeLists-xmlParser.txt.in b/CMakeLists-xmlParser.txt.in deleted file mode 100644 index e7289e3..0000000 --- a/CMakeLists-xmlParser.txt.in +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required( VERSION 2.8.7 ) - -include(ExternalProject) - -ExternalProject_Add(xmlParser - GIT_REPOSITORY https://github.com/LBNL-ETA/XMLParser.git - GIT_TAG "v1.0.1" - - UPDATE_COMMAND "" - PATCH_COMMAND "" - - SOURCE_DIR "${CMAKE_BINARY_DIR}/xmlParser-src" - BINARY_DIR "${CMAKE_BINARY_DIR}/xmlParser-build" - - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - TEST_COMMAND "" - INSTALL_COMMAND "" -) diff --git a/CMakeLists.txt b/CMakeLists.txt index 543a8b9..e8eb1a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.11) project( THMXParser VERSION 1.1.0 LANGUAGES CXX ) set(LIB_NAME ${PROJECT_NAME}) @@ -33,7 +33,17 @@ else() set(DOWNLOAD_GTEST OFF) endif() -include(CMakeLists-xmlParser.txt) +include(FetchContent) + +if(NOT TARGET xmlParser) + FetchContent_Declare( + xmlParser + GIT_REPOSITORY https://github.com/LBNL-ETA/XMLParser.git + GIT_TAG "v1.0.1" + ) + + FetchContent_MakeAvailable(xmlParser) +endif() add_subdirectory( src ) @@ -50,6 +60,10 @@ Option(BUILD_THMX_Parser_Tests "Build tests for thmx file parsing." ON) if(BUILD_THMX_Parser_Tests) enable_testing() add_subdirectory( test ) + + # Set the path to the test directory + set(TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test") + target_compile_definitions(THMXParser-test PRIVATE TEST_DATA_DIR="${TEST_DATA_DIR}") endif() diff --git a/src/thmxParser.cpp b/src/thmxParser.cpp index c8a536d..f865d56 100644 --- a/src/thmxParser.cpp +++ b/src/thmxParser.cpp @@ -97,7 +97,11 @@ namespace thmxParser // int shadeID = std::stoi( str ); str = getAttribute(materialNode, "RGBColor"); unsigned int red, green, blue; +#ifdef _MSC_VER + sscanf_s(str.c_str(), "0x%02x%02x%02x", &red, &green, &blue); +#else std::sscanf(str.c_str(), "0x%02x%02x%02x", &red, &green, &blue); +#endif ColorRGB color{red, green, blue}; int cavityModel = 0; str = getAttribute(materialNode, "CavityModel"); @@ -172,7 +176,11 @@ namespace thmxParser float temperature = std::stof(str); str = getAttribute(bcondNode, "RGBColor"); unsigned int red, green, blue; +#ifdef _MSC_VER + sscanf_s(str.c_str(), "0x%02x%02x%02x", &red, &green, &blue); +#else std::sscanf(str.c_str(), "0x%02x%02x%02x", &red, &green, &blue); +#endif ColorRGB color{red, green, blue}; str = getAttribute(bcondNode, "Tr"); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9e3989b..32ad12f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,8 +32,8 @@ endif() add_executable(${PROJECT_TEST_NAME} read_cs_03.unit.cpp read_cma_example.cpp - main.cpp - paths.h ) + main.cpp +) include_directories(${PROJECT_SOURCE_DIR}/src) diff --git a/test/main.cpp b/test/main.cpp index 00632d6..2c539a5 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,16 +1,11 @@ #include -#include "paths.h" - -std::string test_dir; - int main( int argc, char* argv[] ) { #ifdef ENABLE_GTEST_DEBUG_MODE ::testing::GTEST_FLAG(break_on_failure) = true; ::testing::GTEST_FLAG(catch_exceptions) = false; #endif ::testing::InitGoogleTest( &argc, argv ); - test_dir = argv[1]; return RUN_ALL_TESTS(); } diff --git a/test/paths.h b/test/paths.h deleted file mode 100644 index 5553bee..0000000 --- a/test/paths.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WINCALC_TESTS_PATHS_H_ -#define WINCALC_TESTS_PATHS_H_ - -#include - -extern std::string test_dir; - -#endif diff --git a/test/read_cma_example.cpp b/test/read_cma_example.cpp index b9bb9c7..7fe011f 100644 --- a/test/read_cma_example.cpp +++ b/test/read_cma_example.cpp @@ -1,32 +1,19 @@ #include #include -#include -#include #include #include "thmxParser.hpp" -#include "paths.h" - -extern std::string test_dir; - -class TestLoadCMA : public testing::Test -{ -protected: - virtual void SetUp() - {} -}; - -TEST_F(TestLoadCMA, TestLoadCMAFromDisk) +TEST(TestLoadCMA, TestLoadCMAFromDisk) { - std::filesystem::path product_path(test_dir); + std::filesystem::path product_path(TEST_DATA_DIR); product_path /= "files"; product_path /= "cma_example.thmx"; auto contents = thmxParser::parseFile(product_path.string()); - EXPECT_EQ(contents.fileVersion, "1"); - EXPECT_EQ(contents.materials.size(), 5); - EXPECT_EQ(contents.boundaryConditions.size(), 4); - EXPECT_EQ(contents.polygons.size(), 5); - EXPECT_EQ(contents.boundaryConditionPolygons.size(), 11); + EXPECT_EQ(contents.fileVersion, "1"); + EXPECT_EQ(contents.materials.size(), 5); + EXPECT_EQ(contents.boundaryConditions.size(), 4); + EXPECT_EQ(contents.polygons.size(), 5); + EXPECT_EQ(contents.boundaryConditionPolygons.size(), 11); } diff --git a/test/read_cs_03.unit.cpp b/test/read_cs_03.unit.cpp index 8298cc9..8bfb192 100644 --- a/test/read_cs_03.unit.cpp +++ b/test/read_cs_03.unit.cpp @@ -1,28 +1,18 @@ #include #include -#include -#include #include #include "thmxParser.hpp" -#include "paths.h" - -extern std::string test_dir; - -class TestLoadCS03 : public testing::Test -{ -protected: - virtual void SetUp() - {} -}; - -TEST_F(TestLoadCS03, TestLoadCS03FromDisk) +TEST(TestLoadCS03, TestLoadCS03FromDisk) { - std::filesystem::path product_path(test_dir); + std::filesystem::path product_path(TEST_DATA_DIR); product_path /= "files"; product_path /= "CS03.thmx"; - //thmxParser::parseFile(product_path.string()); - + auto contents = thmxParser::parseFile(product_path.string()); + EXPECT_EQ(contents.fileVersion, "1"); + EXPECT_EQ(contents.boundaryConditions.size(), 4u); + EXPECT_EQ(contents.materials.size(), 13u); + EXPECT_EQ(contents.polygons.size(), 99u); }