All checks were successful
Test compiling project / test (push) Successful in 2m21s
149 lines
4.5 KiB
C++
149 lines
4.5 KiB
C++
#include <unity.h>
|
|
#include <string.h>
|
|
#include <utils.cpp>
|
|
|
|
void test_latest_configuration_major() {
|
|
Configuration configs[] = {
|
|
{Version{1, 9, 9}, "url1", "Board1", "Config1"},
|
|
{Version{2, 8, 8}, "url2", "Board2", "Config2"},
|
|
{Version{3, 5, 1}, "url3", "Board3", "Config3"}
|
|
};
|
|
|
|
Configuration latest = getLatestConfiguration(configs, 3);
|
|
TEST_ASSERT_EQUAL(latest.version.major, 3);
|
|
TEST_ASSERT_EQUAL(latest.version.minor, 5);
|
|
TEST_ASSERT_EQUAL(latest.version.patch, 1);
|
|
}
|
|
|
|
void test_latest_configuration_minor() {
|
|
Configuration configs[] = {
|
|
{Version{1, 7, 9}, "url1", "Board1", "Config1"},
|
|
{Version{1, 8, 8}, "url2", "Board2", "Config2"},
|
|
{Version{1, 5, 1}, "url3", "Board3", "Config3"}
|
|
};
|
|
|
|
Configuration latest = getLatestConfiguration(configs, 3);
|
|
TEST_ASSERT_EQUAL(latest.version.major, 1);
|
|
TEST_ASSERT_EQUAL(latest.version.minor, 8);
|
|
TEST_ASSERT_EQUAL(latest.version.patch, 8);
|
|
}
|
|
|
|
void test_latest_configuration_patch() {
|
|
Configuration configs[] = {
|
|
{Version{1, 4, 4}, "url1", "Board1", "Config1"},
|
|
{Version{1, 4, 7}, "url2", "Board2", "Config2"},
|
|
{Version{1, 4, 2}, "url3", "Board3", "Config3"}
|
|
};
|
|
|
|
Configuration latest = getLatestConfiguration(configs, 3);
|
|
TEST_ASSERT_EQUAL(latest.version.major, 1);
|
|
TEST_ASSERT_EQUAL(latest.version.minor, 4);
|
|
TEST_ASSERT_EQUAL(latest.version.patch, 7);
|
|
}
|
|
|
|
|
|
void test_parse_version_valid_input() {
|
|
Version v = parseVersion("1.2.3");
|
|
TEST_ASSERT_EQUAL(1, v.major);
|
|
TEST_ASSERT_EQUAL(2, v.minor);
|
|
TEST_ASSERT_EQUAL(3, v.patch);
|
|
}
|
|
|
|
void test_parse_version_valid_input_2() {
|
|
Version v = parseVersion("61.5231.4212");
|
|
TEST_ASSERT_EQUAL(61, v.major);
|
|
TEST_ASSERT_EQUAL(5231, v.minor);
|
|
TEST_ASSERT_EQUAL(4212, v.patch);
|
|
}
|
|
|
|
void test_parse_version_missing_parts() {
|
|
Version v = parseVersion("1.2");
|
|
TEST_ASSERT_EQUAL(1, v.major);
|
|
TEST_ASSERT_EQUAL(2, v.minor);
|
|
TEST_ASSERT_EQUAL(0, v.patch);
|
|
}
|
|
|
|
void test_parse_version_more_missing_parts() {
|
|
Version v = parseVersion("1");
|
|
TEST_ASSERT_EQUAL(1, v.major);
|
|
TEST_ASSERT_EQUAL(0, v.minor);
|
|
TEST_ASSERT_EQUAL(0, v.patch);
|
|
}
|
|
|
|
void test_parse_version_invalid_format() {
|
|
Version v = parseVersion("invalid");
|
|
TEST_ASSERT_EQUAL(0, v.major);
|
|
TEST_ASSERT_EQUAL(0, v.minor);
|
|
TEST_ASSERT_EQUAL(0, v.patch);
|
|
}
|
|
|
|
void test_parse_version_extra_content() {
|
|
Version v = parseVersion("1.2.3-extra");
|
|
TEST_ASSERT_EQUAL(0, v.major);
|
|
TEST_ASSERT_EQUAL(0, v.minor);
|
|
TEST_ASSERT_EQUAL(0, v.patch);
|
|
}
|
|
|
|
void test_is_version_newer_major() {
|
|
Version oldVersion = {1, 3, 4};
|
|
Version newVersion = {2, 1, 1};
|
|
TEST_ASSERT_TRUE(isVersionNewer(oldVersion, newVersion));
|
|
}
|
|
|
|
void test_is_version_newer_minor() {
|
|
Version oldVersion = {1, 0, 8};
|
|
Version newVersion = {1, 1, 0};
|
|
TEST_ASSERT_TRUE(isVersionNewer(oldVersion, newVersion));
|
|
}
|
|
|
|
void test_is_version_newer_patch() {
|
|
Version oldVersion = {1, 1, 1};
|
|
Version newVersion = {1, 1, 2};
|
|
TEST_ASSERT_TRUE(isVersionNewer(oldVersion, newVersion));
|
|
}
|
|
|
|
void test_is_version_not_newer_same() {
|
|
Version oldVersion = {1, 1, 1};
|
|
Version newVersion = {1, 1, 1};
|
|
TEST_ASSERT_FALSE(isVersionNewer(oldVersion, newVersion));
|
|
}
|
|
|
|
void test_is_version_not_newer_major() {
|
|
Version oldVersion = {2, 0, 0};
|
|
Version newVersion = {1, 99, 99};
|
|
TEST_ASSERT_FALSE(isVersionNewer(oldVersion, newVersion));
|
|
}
|
|
|
|
void test_is_version_not_newer_minor() {
|
|
Version oldVersion = {1, 2, 0};
|
|
Version newVersion = {1, 1, 99};
|
|
TEST_ASSERT_FALSE(isVersionNewer(oldVersion, newVersion));
|
|
}
|
|
|
|
void test_is_version_not_newer_patch() {
|
|
Version oldVersion = {1, 1, 2};
|
|
Version newVersion = {1, 1, 1};
|
|
TEST_ASSERT_FALSE(isVersionNewer(oldVersion, newVersion));
|
|
}
|
|
|
|
|
|
int main() {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_latest_configuration_major);
|
|
RUN_TEST(test_latest_configuration_minor);
|
|
RUN_TEST(test_latest_configuration_patch);
|
|
RUN_TEST(test_parse_version_valid_input);
|
|
RUN_TEST(test_parse_version_missing_parts);
|
|
RUN_TEST(test_parse_version_invalid_format);
|
|
RUN_TEST(test_parse_version_extra_content);
|
|
RUN_TEST(test_parse_version_valid_input_2);
|
|
RUN_TEST(test_parse_version_more_missing_parts);
|
|
RUN_TEST(test_is_version_newer_major);
|
|
RUN_TEST(test_is_version_newer_minor);
|
|
RUN_TEST(test_is_version_newer_patch);
|
|
RUN_TEST(test_is_version_not_newer_same);
|
|
RUN_TEST(test_is_version_not_newer_major);
|
|
RUN_TEST(test_is_version_not_newer_minor);
|
|
RUN_TEST(test_is_version_not_newer_patch);
|
|
UNITY_END();
|
|
} |