Skip to content

Commit 584e664

Browse files
committed
Add test
1 parent 4ebaa7c commit 584e664

File tree

5 files changed

+221
-0
lines changed

5 files changed

+221
-0
lines changed

test/common_main.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
main for UnitTest on native
8+
*/
9+
#include <gtest/gtest.h>
10+
11+
// C++ version
12+
#if __cplusplus >= 202002L
13+
#pragma message "C++20 or later"
14+
#elif __cplusplus >= 201703L
15+
#pragma message "C++17 or later"
16+
#elif __cplusplus >= 201402L
17+
#pragma message "C++14 or later"
18+
#elif __cplusplus >= 201103L
19+
#pragma message "C++11 or later"
20+
#else
21+
#error "Need C++11 or later"
22+
#endif
23+
// Compiler
24+
#if defined(__clang__)
25+
#pragma message "Clang"
26+
#elif defined(_MSC_VER)
27+
#pragma message "MSVC"
28+
#elif defined(__BORLANDC__)
29+
#pragma message "BORLANDC"
30+
#elif defined(__MINGW32__) || defined(__MINGW64__)
31+
#pragma message "MINGW"
32+
#elif defined(__INTEL_COMPILER)
33+
#pragma message "ICC"
34+
#elif defined(__GNUG__)
35+
#pragma message "GCC"
36+
#else
37+
#pragma message "Unknown compiler"
38+
#endif
39+
40+
/*
41+
For native test, this main() is used.
42+
If the Arduino framework is used, the framework library main is used.
43+
*/
44+
#if !defined(ARDUINO)
45+
int main(int argc, char **argv)
46+
{
47+
testing::InitGoogleTest(&argc, argv);
48+
49+
#ifdef GTEST_FILTER
50+
::testing::GTEST_FLAG(filter) = GTEST_FILTER;
51+
#endif
52+
53+
#pragma GCC diagnostic push
54+
#pragma GCC diagnostic ignored "-Wunused-result"
55+
RUN_ALL_TESTS();
56+
#pragma GCC diagnostic pop
57+
// Always return zero-code and allow PlatformIO to parse results
58+
return 0;
59+
}
60+
#endif

test/embedded/embedded_main.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
main for UnitTest on embedded
8+
*/
9+
#include <gtest/gtest.h>
10+
#include <M5Unified.h>
11+
#include <esp_system.h>
12+
13+
#pragma message "Embedded setup/loop"
14+
15+
#if __has_include(<esp_idf_version.h>)
16+
#include <esp_idf_version.h>
17+
#else // esp_idf_version.h has been introduced in Arduino 1.0.5 (ESP-IDF3.3)
18+
#define ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
19+
#define ESP_IDF_VERSION ESP_IDF_VERSION_VAL(3, 2, 0)
20+
#endif
21+
22+
namespace {
23+
auto& lcd = M5.Display;
24+
} // namespace
25+
26+
void test()
27+
{
28+
lcd.fillRect(0, 0, lcd.width() >> 1, lcd.height(), RUN_ALL_TESTS() ? TFT_RED : TFT_GREEN);
29+
}
30+
31+
void setup()
32+
{
33+
delay(1500);
34+
35+
M5.begin();
36+
37+
M5_LOGI("CPP %ld", __cplusplus);
38+
M5_LOGI("ESP-IDF Version %d.%d.%d", (ESP_IDF_VERSION >> 16) & 0xFF, (ESP_IDF_VERSION >> 8) & 0xFF,
39+
ESP_IDF_VERSION & 0xFF);
40+
M5_LOGI("BOARD:%X", M5.getBoard());
41+
M5_LOGI("Heap: %u", esp_get_free_heap_size());
42+
43+
lcd.clear(TFT_DARKGRAY);
44+
::testing::InitGoogleTest();
45+
46+
#ifdef GTEST_FILTER
47+
::testing::GTEST_FLAG(filter) = GTEST_FILTER;
48+
#endif
49+
}
50+
51+
void loop()
52+
{
53+
test();
54+
#if 0
55+
delay(1000);
56+
esp_restart();
57+
#endif
58+
while (true) {
59+
delay(10000);
60+
}
61+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
UnitTest for SYN115
8+
*/
9+
#include <gtest/gtest.h>
10+
#include <Wire.h>
11+
#include <M5Unified.h>
12+
#include <M5UnitUnified.hpp>
13+
#include <googletest/test_template.hpp>
14+
#include <unit/unit_SYN115.hpp>
15+
#include <chrono>
16+
#include <cmath>
17+
#include <iostream>
18+
#include <vector>
19+
20+
using namespace m5::unit::googletest;
21+
using namespace m5::unit;
22+
using namespace m5::unit::rf433;
23+
using namespace m5::unit::types;
24+
25+
const ::testing::Environment* global_fixture = ::testing::AddGlobalTestEnvironment(new GlobalFixture<400000U>());
26+
27+
class TestSYN115 : public GPIOComponentTestBase<UnitSYN115, bool> {
28+
protected:
29+
virtual UnitSYN115* get_instance() override
30+
{
31+
auto ptr = new m5::unit::UnitSYN115();
32+
return ptr;
33+
}
34+
virtual bool is_using_hal() const override
35+
{
36+
return GetParam();
37+
};
38+
};
39+
40+
// INSTANTIATE_TEST_SUITE_P(ParamValues, TestSYN115, ::testing::Values(false, true));
41+
// INSTANTIATE_TEST_SUITE_P(ParamValues, TestSYN115,::testing::Values(true));
42+
INSTANTIATE_TEST_SUITE_P(ParamValues, TestSYN115, ::testing::Values(false));
43+
44+
namespace {
45+
} // namespace
46+
47+
TEST_P(TestSYN115, Basic)
48+
{
49+
SCOPED_TRACE(ustr);
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
UnitTest for SYN531R
8+
*/
9+
#include <gtest/gtest.h>
10+
#include <Wire.h>
11+
#include <M5Unified.h>
12+
#include <M5UnitUnified.hpp>
13+
#include <googletest/test_template.hpp>
14+
#include <unit/unit_SYN531R.hpp>
15+
#include <chrono>
16+
#include <cmath>
17+
#include <iostream>
18+
#include <vector>
19+
20+
using namespace m5::unit::googletest;
21+
using namespace m5::unit;
22+
using namespace m5::unit::rf433;
23+
using namespace m5::unit::types;
24+
25+
const ::testing::Environment* global_fixture = ::testing::AddGlobalTestEnvironment(new GlobalFixture<400000U>());
26+
27+
class TestSYN531R : public GPIOComponentTestBase<UnitSYN531R, bool> {
28+
protected:
29+
virtual UnitSYN531R* get_instance() override
30+
{
31+
auto ptr = new m5::unit::UnitSYN531R();
32+
return ptr;
33+
}
34+
virtual bool is_using_hal() const override
35+
{
36+
return GetParam();
37+
};
38+
};
39+
40+
// INSTANTIATE_TEST_SUITE_P(ParamValues, TestSYN531R, ::testing::Values(false, true));
41+
// INSTANTIATE_TEST_SUITE_P(ParamValues, TestSYN531R,::testing::Values(true));
42+
INSTANTIATE_TEST_SUITE_P(ParamValues, TestSYN531R, ::testing::Values(false));
43+
44+
namespace {
45+
} // namespace
46+
47+
TEST_P(TestSYN531R, Basic)
48+
{
49+
SCOPED_TRACE(ustr);
50+
}

test/native/test_dummy/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)