From f26ea2028c1034dde1224663a2b845495f39ac44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= Date: Sun, 14 Feb 2016 12:13:59 +0100 Subject: [PATCH] unittests: added some unittests for the color module --- tests/unittests/tests-color/Makefile | 1 + tests/unittests/tests-color/Makefile.include | 1 + tests/unittests/tests-color/tests-color.c | 95 ++++++++++++++++++++ tests/unittests/tests-color/tests-color.h | 37 ++++++++ 4 files changed, 134 insertions(+) create mode 100644 tests/unittests/tests-color/Makefile create mode 100644 tests/unittests/tests-color/Makefile.include create mode 100644 tests/unittests/tests-color/tests-color.c create mode 100644 tests/unittests/tests-color/tests-color.h diff --git a/tests/unittests/tests-color/Makefile b/tests/unittests/tests-color/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/tests/unittests/tests-color/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-color/Makefile.include b/tests/unittests/tests-color/Makefile.include new file mode 100644 index 0000000000..568ef98033 --- /dev/null +++ b/tests/unittests/tests-color/Makefile.include @@ -0,0 +1 @@ +USEMODULE += color diff --git a/tests/unittests/tests-color/tests-color.c b/tests/unittests/tests-color/tests-color.c new file mode 100644 index 0000000000..0ae9bb0f57 --- /dev/null +++ b/tests/unittests/tests-color/tests-color.c @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2016 Cenk Gündoğan + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + */ +#include +#include + +#include "embUnit/embUnit.h" + +#include "color.h" + +#include "tests-color.h" + +static void test_str2rgb_upper_case__success(void) +{ + const char *color_str = "F09A1D"; + color_rgb_t rgb; + + color_str2rgb(color_str, &rgb); + TEST_ASSERT_EQUAL_INT(0xF0, rgb.r); + TEST_ASSERT_EQUAL_INT(0x9A, rgb.g); + TEST_ASSERT_EQUAL_INT(0x1D, rgb.b); +} + +static void test_str2rgb_lower_case__success(void) +{ + const char *color_str = "f09a1d"; + color_rgb_t rgb; + + color_str2rgb(color_str, &rgb); + TEST_ASSERT_EQUAL_INT(0xF0, rgb.r); + TEST_ASSERT_EQUAL_INT(0x9A, rgb.g); + TEST_ASSERT_EQUAL_INT(0x1D, rgb.b); +} + +static void test_rgb2str__success(void) +{ + char color_str[7] = { 0 }; + const color_rgb_t rgb = { .r = 0x0A, .g = 0xB1, .b = 0x3C }; + + color_rgb2str(&rgb, color_str); + + TEST_ASSERT_EQUAL_STRING("0AB13C", (char *) color_str); +} + +static void test_hex2rgb__success(void) +{ + const uint32_t hex = 0x8Fa1b9; + color_rgb_t rgb; + + color_hex2rgb(hex, &rgb); + TEST_ASSERT_EQUAL_INT(0x8F, rgb.r); + TEST_ASSERT_EQUAL_INT(0xA1, rgb.g); + TEST_ASSERT_EQUAL_INT(0xB9, rgb.b); +} + +static void test_rgb2hex__success(void) +{ + uint32_t hex = 0x0; + const color_rgb_t rgb = { .r = 0x0A, .g = 0xB1, .b = 0x3C }; + + color_rgb2hex(&rgb, &hex); + + TEST_ASSERT_EQUAL_INT(0x000AB13C, hex); +} + +Test *tests_color_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(test_str2rgb_upper_case__success), + new_TestFixture(test_str2rgb_lower_case__success), + new_TestFixture(test_hex2rgb__success), + new_TestFixture(test_rgb2hex__success), + new_TestFixture(test_rgb2str__success), + }; + + EMB_UNIT_TESTCALLER(color_tests, NULL, NULL, fixtures); + + return (Test *)&color_tests; +} + +void tests_color(void) +{ + TESTS_RUN(tests_color_tests()); +} +/** @} */ diff --git a/tests/unittests/tests-color/tests-color.h b/tests/unittests/tests-color/tests-color.h new file mode 100644 index 0000000000..64c6e760c6 --- /dev/null +++ b/tests/unittests/tests-color/tests-color.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2016 Cenk Gündoğan + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @addtogroup unittests + * @{ + * + * @file + * @brief Unittests for the ``color`` module + * + * @author Cenk Gündoğan + */ +#ifndef TESTS_COLOR_H +#define TESTS_COLOR_H + +#include "embUnit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The entry point of this test suite. + */ +void tests_color(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_COLOR_H */ +/** @} */