Skip to content

Commit

Permalink
MMCore: Switch from GoogleTest to Catch2
Browse files Browse the repository at this point in the history
  • Loading branch information
marktsuchida committed Dec 18, 2023
1 parent 9d625c3 commit b4a80f1
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 281 deletions.
2 changes: 1 addition & 1 deletion MMCore/subprojects/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
/*.wrap

# Do not ignore wraps we provide
!/gtest.wrap
!/catch2.wrap
11 changes: 11 additions & 0 deletions MMCore/subprojects/catch2.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[wrap-file]
directory = Catch2-3.4.0
source_url = https://github.com/catchorg/Catch2/archive/v3.4.0.tar.gz
source_filename = Catch2-3.4.0.tar.gz
source_hash = 122928b814b75717316c71af69bd2b43387643ba076a6ec16e7882bfb2dfacbb
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.4.0-1/Catch2-3.4.0.tar.gz
wrapdb_version = 3.4.0-1

[provide]
catch2 = catch2_dep
catch2-with-main = catch2_with_main_dep
16 changes: 0 additions & 16 deletions MMCore/subprojects/gtest.wrap

This file was deleted.

78 changes: 39 additions & 39 deletions MMCore/unittest/APIError-Tests.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <gtest/gtest.h>
#include <catch2/catch_all.hpp>

#include "MMCore.h"

TEST(APIErrorTests, SetFocusDirectionWithInvalidDevice)
TEST_CASE("setFocusDirection with invalid device", "[APIError]")
{
CMMCore c;
// Must not throw or crash
Expand All @@ -20,68 +20,68 @@ TEST(APIErrorTests, SetFocusDirectionWithInvalidDevice)
c.setFocusDirection("Core", -1);
}

TEST(APIErrorTests, GetNumberOfStatesWithInvalidDevice)
TEST_CASE("getNumberOfStates with invalid device", "[APIError]")
{
CMMCore c;
// Must not throw or crash
EXPECT_EQ(-1, c.getNumberOfStates(nullptr));
EXPECT_EQ(-1, c.getNumberOfStates(""));
EXPECT_EQ(-1, c.getNumberOfStates("Blah"));
EXPECT_EQ(-1, c.getNumberOfStates("Core"));
CHECK(c.getNumberOfStates(nullptr) == -1);
CHECK(c.getNumberOfStates("") == -1);
CHECK(c.getNumberOfStates("Blah") == -1);
CHECK(c.getNumberOfStates("Core") == -1);
}

TEST(APIErrorTests, GetAvailableConfigsWithInvalidGroup)
TEST_CASE("getAvailableConfigs with invalid group", "[APIError]")
{
CMMCore c;
EXPECT_TRUE(c.getAvailableConfigs(nullptr).empty());
EXPECT_TRUE(c.getAvailableConfigs("").empty());
EXPECT_TRUE(c.getAvailableConfigs("Blah").empty());
CHECK(c.getAvailableConfigs(nullptr).empty());
CHECK(c.getAvailableConfigs("").empty());
CHECK(c.getAvailableConfigs("Blah").empty());
}

TEST(APIErrorTests, GetPixelSizeUmWithNoConfig)
TEST_CASE("getPixelSizeUm with no config", "[APIError]")
{
CMMCore c;
EXPECT_EQ(0.0, c.getPixelSizeUm(false));
EXPECT_EQ(0.0, c.getPixelSizeUm(true));
CHECK(c.getPixelSizeUm(false) == 0.0);
CHECK(c.getPixelSizeUm(true) == 0.0);
}

TEST(APIErrorTests, IsConfigDefinedWithNullArgs)
TEST_CASE("isConfigDefined with null args", "[APIError]")
{
CMMCore c;
EXPECT_FALSE(c.isConfigDefined(nullptr, "Blah"));
EXPECT_FALSE(c.isConfigDefined("Blah", nullptr));
EXPECT_FALSE(c.isConfigDefined(nullptr, nullptr));
EXPECT_FALSE(c.isConfigDefined("Blah", "Blah"));
EXPECT_FALSE(c.isConfigDefined(nullptr, ""));
EXPECT_FALSE(c.isConfigDefined("", nullptr));
EXPECT_FALSE(c.isConfigDefined(nullptr, nullptr));
EXPECT_FALSE(c.isConfigDefined("", ""));
EXPECT_FALSE(c.isConfigDefined("", "Blah"));
EXPECT_FALSE(c.isConfigDefined("Blah", ""));
CHECK_FALSE(c.isConfigDefined(nullptr, "Blah"));
CHECK_FALSE(c.isConfigDefined("Blah", nullptr));
CHECK_FALSE(c.isConfigDefined(nullptr, nullptr));
CHECK_FALSE(c.isConfigDefined("Blah", "Blah"));
CHECK_FALSE(c.isConfigDefined(nullptr, ""));
CHECK_FALSE(c.isConfigDefined("", nullptr));
CHECK_FALSE(c.isConfigDefined(nullptr, nullptr));
CHECK_FALSE(c.isConfigDefined("", ""));
CHECK_FALSE(c.isConfigDefined("", "Blah"));
CHECK_FALSE(c.isConfigDefined("Blah", ""));
}

TEST(APIErrorTests, IsGroupDefinedWithNullArg)
TEST_CASE("isGroupDefined with null arg", "[APIError]")
{
CMMCore c;
EXPECT_FALSE(c.isGroupDefined(nullptr));
EXPECT_FALSE(c.isGroupDefined(""));
EXPECT_FALSE(c.isGroupDefined("Blah"));
CHECK_FALSE(c.isGroupDefined(nullptr));
CHECK_FALSE(c.isGroupDefined(""));
CHECK_FALSE(c.isGroupDefined("Blah"));
}

TEST(APIErrorTests, SupportsDeviceDetectionWithInvalidDevice)
TEST_CASE("supportsDeviceDetection with invalid device", "[APIError]")
{
CMMCore c;
EXPECT_FALSE(c.supportsDeviceDetection(nullptr));
EXPECT_FALSE(c.supportsDeviceDetection(""));
EXPECT_FALSE(c.supportsDeviceDetection("Blah"));
EXPECT_FALSE(c.supportsDeviceDetection("Core"));
CHECK_FALSE(c.supportsDeviceDetection(nullptr));
CHECK_FALSE(c.supportsDeviceDetection(""));
CHECK_FALSE(c.supportsDeviceDetection("Blah"));
CHECK_FALSE(c.supportsDeviceDetection("Core"));
}

TEST(APIErrorTests, DetectDeviceWithInvalidDevice)
TEST_CASE("detectDevice with invalid device", "[APIError]")
{
CMMCore c;
EXPECT_EQ(MM::Unimplemented, c.detectDevice(nullptr));
EXPECT_EQ(MM::Unimplemented, c.detectDevice(""));
EXPECT_EQ(MM::Unimplemented, c.detectDevice("Blah"));
EXPECT_EQ(MM::Unimplemented, c.detectDevice("Core"));
CHECK(c.detectDevice(nullptr) == MM::Unimplemented);
CHECK(c.detectDevice("") == MM::Unimplemented);
CHECK(c.detectDevice("Blah") == MM::Unimplemented);
CHECK(c.detectDevice("Core") == MM::Unimplemented);
}
25 changes: 25 additions & 0 deletions MMCore/unittest/CoreCreateDestroy-Tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <catch2/catch_all.hpp>

#include "MMCore.h"

TEST_CASE("CMMCore create and destroy twice", "[CoreCreateDestroy]")
{
{
CMMCore c1;
}
{
CMMCore c2;
}
}

TEST_CASE("CMMCore create two at once", "[CoreCreateDestroy]")
{
CMMCore c1;
CMMCore c2;
}

TEST_CASE("CMMCore create and reset", "[CoreCreateDestroy]")
{
CMMCore c;
c.reset();
}
25 changes: 0 additions & 25 deletions MMCore/unittest/CoreSanity-Tests.cpp

This file was deleted.

21 changes: 12 additions & 9 deletions MMCore/unittest/Logger-Tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <gtest/gtest.h>
#include <catch2/catch_all.hpp>

#include "Logging/Logging.h"

Expand All @@ -8,10 +8,10 @@
#include <thread>
#include <vector>

using namespace mm::logging;
namespace mm {
namespace logging {


TEST(LoggerTests, BasicSynchronous)
TEST_CASE("synchronous logger basics", "[Logger]")
{
std::shared_ptr<LoggingCore> c =
std::make_shared<LoggingCore>();
Expand All @@ -26,7 +26,7 @@ TEST(LoggerTests, BasicSynchronous)
}


TEST(LoggerTests, BasicAsynchronous)
TEST_CASE("asynchronous logger basics", "[Logger]")
{
std::shared_ptr<LoggingCore> c =
std::make_shared<LoggingCore>();
Expand All @@ -41,7 +41,7 @@ TEST(LoggerTests, BasicAsynchronous)
}


TEST(LoggerTests, BasicLogStream)
TEST_CASE("log stream basics", "[Logger]")
{
std::shared_ptr<LoggingCore> c =
std::make_shared<LoggingCore>();
Expand Down Expand Up @@ -80,7 +80,7 @@ class LoggerTestThreadFunc
};


TEST(LoggerTests, SyncAndThreaded)
TEST_CASE("sync logger on thread", "[Logger]")
{
std::shared_ptr<LoggingCore> c =
std::make_shared<LoggingCore>();
Expand All @@ -100,7 +100,7 @@ TEST(LoggerTests, SyncAndThreaded)
}


TEST(LoggerTests, AsyncAndThreaded)
TEST_CASE("async logger on thread", "[Logger]")
{
std::shared_ptr<LoggingCore> c =
std::make_shared<LoggingCore>();
Expand All @@ -117,4 +117,7 @@ TEST(LoggerTests, AsyncAndThreaded)
}
for (unsigned i = 0; i < threads.size(); ++i)
threads[i]->join();
}
}

} // namespace logging
} // namespace mm
Loading

0 comments on commit b4a80f1

Please sign in to comment.