Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Code Coverage

on:
pull_request:
branches: [ main ]
branches: [ develop ]

jobs:
execute-unit-code-coverage-report-on-release:
Expand Down
10 changes: 8 additions & 2 deletions systimerfactory/unittest/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#

# Define the program name and the source files
bin_PROGRAMS = drmtest_gtest dtttest_gtest rdkDefaulttest_gtest
bin_PROGRAMS = drmtest_gtest dtttest_gtest rdkDefaulttest_gtest timerfactory_gtest

# Define the include directories
COMMON_CPPFLAGS = -I../ -I../../ -I../../interface -I./mocks -I/usr/include

# Define the libraries to link against
COMMON_LDADD = -ljsoncpp -lgtest -lgtest_main -lgmock_main -lgmock
COMMON_LDADD = -ljsoncpp -lgtest -lgtest_main -lgmock_main -lgmock

# Define the compiler flags
COMMON_CXXFLAGS = -frtti
Expand All @@ -32,6 +32,7 @@ COMMON_CXXFLAGS = -frtti
drmtest_gtest_SOURCES = drmtimerUnitTest.cpp
dtttest_gtest_SOURCES = dtttimerUnitTest.cpp
rdkDefaulttest_gtest_SOURCES = rdkDefaulttimesyncUnitTest.cpp
timerfactory_gtest_SOURCES = timerfactory_gtest.cpp

# Apply common properties to each program
drmtest_gtest_CPPFLAGS = $(COMMON_CPPFLAGS)
Expand All @@ -45,3 +46,8 @@ dtttest_gtest_CXXFLAGS = $(COMMON_CXXFLAGS)
rdkDefaulttest_gtest_CPPFLAGS = $(COMMON_CPPFLAGS)
rdkDefaulttest_gtest_LDADD = $(COMMON_LDADD)
rdkDefaulttest_gtest_CXXFLAGS = $(COMMON_CXXFLAGS)


timerfactory_gtest_CPPFLAGS = $(COMMON_CPPFLAGS)
timerfactory_gtest_LDADD = $(COMMON_LDADD)
timerfactory_gtest_CXXFLAGS = $(COMMON_CXXFLAGS)
131 changes: 131 additions & 0 deletions systimerfactory/unittest/timerfactory_gtest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@



#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <string>
using namespace std;

// ------------------- Interfaces -------------------

class ITimeSrc {
public:
virtual ~ITimeSrc() {}
};

class ITimeSync {
public:
virtual ~ITimeSync() {}
};

// ------------------- Mock Classes -------------------

class MockNtpTimeSrc : public ITimeSrc {};
class MockSttTimeSrc : public ITimeSrc {};
class MockRegularTimeSrc : public ITimeSrc {
public:
MockRegularTimeSrc(string arg) {}
};
class MockDrmTimeSrc : public ITimeSrc {
public:
MockDrmTimeSrc(string arg) {}
};
class MockDttTimeSrc : public ITimeSrc {
public:
MockDttTimeSrc(string arg) {}
};

class MockTestTimeSync : public ITimeSync {
public:
MockTestTimeSync(string arg) {}
};
class MockRdkDefaultTimeSync : public ITimeSync {};
class MockTeeTimeSync : public ITimeSync {};

// ------------------- Mocked Factory -------------------
// This replaces your real `timerfactory.cpp` during tests

ITimeSrc* createTimeSrc(string type, string args)
{
if (type == "ntp") return new MockNtpTimeSrc();
else if (type == "stt") return new MockSttTimeSrc();
else if (type == "regular") return new MockRegularTimeSrc(args);
else if (type == "drm") return new MockDrmTimeSrc(args);
#ifdef DTT_ENABLED
else if (type == "dtt") return new MockDttTimeSrc(args);
#endif
return nullptr;
}

ITimeSync* createTimeSync(string type, string args)
{
if (type == "test") return new MockTestTimeSync(args);
else if (type == "rdkdefault") return new MockRdkDefaultTimeSync();
#ifdef TEE_ENABLED
else if (type == "tee") return new MockTeeTimeSync();
#endif
return nullptr;
}

// ------------------- Test Cases -------------------

#define ASSERT_CAST_AND_DELETE(ptr, Type) \
{ auto p = dynamic_cast<Type*>(ptr); ASSERT_NE(p, nullptr); delete p; }

// createTimeSrc tests

TEST(TimerFactoryMockTest, CreateNtpTimeSrc) {
auto* src = createTimeSrc("ntp", "");
ASSERT_CAST_AND_DELETE(src, MockNtpTimeSrc);
}

TEST(TimerFactoryMockTest, CreateSttTimeSrc) {
auto* src = createTimeSrc("stt", "");
ASSERT_CAST_AND_DELETE(src, MockSttTimeSrc);
}

TEST(TimerFactoryMockTest, CreateRegularTimeSrc) {
auto* src = createTimeSrc("regular", "param");
ASSERT_CAST_AND_DELETE(src, MockRegularTimeSrc);
}

TEST(TimerFactoryMockTest, CreateDrmTimeSrc) {
auto* src = createTimeSrc("drm", "/path");
ASSERT_CAST_AND_DELETE(src, MockDrmTimeSrc);
}

#ifdef DTT_ENABLED
TEST(TimerFactoryMockTest, CreateDttTimeSrc) {
auto* src = createTimeSrc("dtt", "data");
ASSERT_CAST_AND_DELETE(src, MockDttTimeSrc);
}
#endif

TEST(TimerFactoryMockTest, CreateInvalidTimeSrcReturnsNullptr) {
auto* src = createTimeSrc("unknown", "xyz");
ASSERT_EQ(src, nullptr);
}

// createTimeSync tests

TEST(TimerFactoryMockTest, CreateTestTimeSync) {
auto* sync = createTimeSync("test", "arg");
ASSERT_CAST_AND_DELETE(sync, MockTestTimeSync);
}

TEST(TimerFactoryMockTest, CreateRdkDefaultTimeSync) {
auto* sync = createTimeSync("rdkdefault", "");
ASSERT_CAST_AND_DELETE(sync, MockRdkDefaultTimeSync);
}

#ifdef TEE_ENABLED
TEST(TimerFactoryMockTest, CreateTeeTimeSync) {
auto* sync = createTimeSync("tee", "");
ASSERT_CAST_AND_DELETE(sync, MockTeeTimeSync);
}
#endif

TEST(TimerFactoryMockTest, CreateInvalidTimeSyncReturnsNullptr) {
auto* sync = createTimeSync("blah", "");
ASSERT_EQ(sync, nullptr);
}
1 change: 1 addition & 0 deletions test/run_ut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ mkdir -p /opt/secure/
./drmtest_gtest
./dtttest_gtest
./rdkDefaulttest_gtest
./timerfactory_gtest

echo "********************"
echo "**** CAPTURE SYSTEM TIMEMANAGER COVERAGE DATA ****"
Expand Down