Skip to content

Commit

Permalink
Merge pull request #420 from micro-manager/mmdevice-mmcore-tests
Browse files Browse the repository at this point in the history
Use Catch2 for MMDevice/MMCore unit tests
  • Loading branch information
marktsuchida authored Dec 22, 2023
2 parents 4b3071e + b4a80f1 commit 108bc1b
Show file tree
Hide file tree
Showing 19 changed files with 358 additions and 508 deletions.
6 changes: 0 additions & 6 deletions MMCore/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,4 @@ libMMCore_la_SOURCES = \
ThreadPool.cpp \
ThreadPool.h

if BUILD_CPP_TESTS
UNITTESTS = unittest
endif

SUBDIRS = . $(UNITTESTS)

EXTRA_DIST = license.txt
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.

84 changes: 39 additions & 45 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,74 +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"));
}

int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
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();
}
31 changes: 0 additions & 31 deletions MMCore/unittest/CoreSanity-Tests.cpp

This file was deleted.

24 changes: 10 additions & 14 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 @@ -119,9 +119,5 @@ TEST(LoggerTests, AsyncAndThreaded)
threads[i]->join();
}


int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
} // namespace logging
} // namespace mm
Loading

0 comments on commit 108bc1b

Please sign in to comment.