Skip to content

Add pure C++ unit tests using Google Test#5

Draft
Copilot wants to merge 6 commits into
masterfrom
copilot/add-cpp-test-project
Draft

Add pure C++ unit tests using Google Test#5
Copilot wants to merge 6 commits into
masterfrom
copilot/add-cpp-test-project

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 31, 2025

Existing tests are C#-only and test C++ functionality indirectly through interop. This adds direct C++ unit tests for OSPSuite.SimModelNative.

Changes

Test Infrastructure

  • New project: tests/OSPSuite.SimModelNative.Tests using Google Test v1.14.0
  • CMakeLists.txt: Unix build with FetchContent for gtest, links against SimModelNative sources
  • vcxproj: Windows build with NuGet gtest package, explicit source file listings
  • Solution integration: Added to Tests folder in OSPSuite.SimModel.sln

Build Integration

  • buildWindows.bat: Builds test executable, runs with XML output
  • buildNix.sh: CMake build for Linux/macOS, executes tests post-build

Test Coverage (200+ assertions)

  • MathHelper: NaN/Inf/finite checks, IsNumeric, Pi, distributions
  • ConstantFormula: Construction, value ops, IsZero, Clone, DE_Jacobian
  • ValuePoint: Constructors, copy semantics, field validation
  • TObjectVector: push_back, clear, indexing, memory management
  • Formula classes: MinFormula, MaxFormula, DivFormula, DiffFormula constructors

Example

TEST_F(MathHelperTest, NormalDistribution) {
    // Test normal distribution at mean
    double result = MathHelper::NormalDistribution(0.0, 1.0, 0.0);
    EXPECT_NEAR(result, 1.0 / std::sqrt(2.0 * MathHelper::Pi()), 1e-10);
    
    // Verify symmetry
    EXPECT_NEAR(
        MathHelper::NormalDistribution(0.0, 1.0, 1.0),
        MathHelper::NormalDistribution(0.0, 1.0, -1.0),
        1e-10
    );
}

Tests run on Windows (x64), Ubuntu (x64/ARM64), and macOS (x64/ARM64) in CI pipeline with XML output artifacts.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add pure C++ tests</issue_title>
<issue_description>The tests in the project https://github.com/Yuri05/OSPSuite.SimModel/tree/master/tests/OSPSuite.SimModel.Tests are all written in C# and test the C++ functionality (encapsulated in the project https://github.com/Yuri05/OSPSuite.SimModel/tree/master/src/OSPSuite.SimModelNative ) only indirectly.

Add the second test project which tests the C++ functionality directly (without relying on C#).

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits October 31, 2025 14:04
Co-authored-by: Yuri05 <25061876+Yuri05@users.noreply.github.com>
Co-authored-by: Yuri05 <25061876+Yuri05@users.noreply.github.com>
Co-authored-by: Yuri05 <25061876+Yuri05@users.noreply.github.com>
Co-authored-by: Yuri05 <25061876+Yuri05@users.noreply.github.com>
Co-authored-by: Yuri05 <25061876+Yuri05@users.noreply.github.com>
Copilot AI changed the title [WIP] Add pure C++ tests for OSPSuite functionality Add pure C++ unit tests using Google Test Oct 31, 2025
Copilot AI requested a review from Yuri05 October 31, 2025 14:14
@Yuri05 Yuri05 marked this pull request as ready for review October 31, 2025 16:12
Copilot AI review requested due to automatic review settings October 31, 2025 16:12
@Yuri05 Yuri05 marked this pull request as draft October 31, 2025 16:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds direct C++ unit testing infrastructure to the OSPSuite.SimModel project using Google Test framework v1.14.0. It introduces a new test project (OSPSuite.SimModelNative.Tests) that tests C++ functionality directly without C# interop, complementing the existing C# tests.

Key changes:

  • New cross-platform test project with Google Test integration (NuGet for Windows, FetchContent for Unix)
  • Build script integration for automated test execution with XML output generation
  • Initial test coverage for core utilities (MathHelper, ConstantFormula), data structures (ValuePoint, TObjectVector), and formula classes

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/OSPSuite.SimModelNative.Tests/CMakeLists.txt CMake configuration for Unix builds with Google Test integration via FetchContent
tests/OSPSuite.SimModelNative.Tests/OSPSuite.SimModelNative.Tests.vcxproj Visual Studio project file for Windows builds with NuGet-based Google Test dependency
tests/OSPSuite.SimModelNative.Tests/OSPSuite.SimModelNative.Tests.vcxproj.filters Project filters organizing test and source files
tests/OSPSuite.SimModelNative.Tests/packages.config NuGet package configuration specifying googletest 1.14.0
tests/OSPSuite.SimModelNative.Tests/README.md Comprehensive documentation for building, running, and extending tests
tests/OSPSuite.SimModelNative.Tests/src/MathHelperTests.cpp Unit tests for MathHelper utilities and ConstantFormula with main() entry point
tests/OSPSuite.SimModelNative.Tests/src/FormulaTests.cpp Basic constructor tests for MinFormula, MaxFormula, DivFormula, DiffFormula
tests/OSPSuite.SimModelNative.Tests/src/ValuePointTests.cpp Tests for ValuePoint constructors, copy semantics, and field validation
tests/OSPSuite.SimModelNative.Tests/src/TObjectVectorTests.cpp Tests for TObjectVector operations including memory management
buildWindows.bat Added C++ test execution with XML output
buildNix.sh Integrated C++ test building and execution in Unix build pipeline
OSPSuite.SimModel.sln Added new test project to Tests solution folder with dependencies
_codeql_detected_source_root CodeQL configuration file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +198 to +201
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main() function should be removed from this test file. Google Test automatically provides a main() function when linking with gtest_main (as configured in CMakeLists.txt line 54). Having a custom main() here creates duplicate symbol conflicts during linking and is redundant.

Suggested change
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pure C++ tests

3 participants