1 // Copyright 2022 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #include "pw_unit_test/static_library_support.h" 16 17 #include "pw_assert/check.h" 18 19 namespace pw::unit_test { 20 21 // Refer to one test in static_library_archived_tests.cc. Do not refer to any 22 // tests in static_library_missing_archived_tests.cc, though; those tests are 23 // expected to be lost because they are not referenced. 24 PW_UNIT_TEST_LINK_FILE_CONTAINING_TEST(StaticLibraryArchivedTest, Test1); 25 26 // Count the number of times each test executes. 27 int test_1_executions = 0; 28 int test_2_executions = 0; 29 30 int test_3_executions_not_expected = 0; 31 int test_4_executions_not_expected = 0; 32 33 class CheckThatTestsRanWhenDestructed { 34 public: ~CheckThatTestsRanWhenDestructed()35 ~CheckThatTestsRanWhenDestructed() { 36 PW_CHECK_INT_EQ(test_1_executions, 1); 37 PW_CHECK_INT_EQ(test_2_executions, 1); 38 39 PW_CHECK_INT_EQ(test_3_executions_not_expected, 0); 40 PW_CHECK_INT_EQ(test_4_executions_not_expected, 0); 41 } 42 } check_that_tests_ran; 43 44 // Test that linking fails if these macros refer to tests that do not exist. 45 // These cannot be a negative compilation tests because they compile 46 // successfully, but fail to link. 47 #if 0 48 49 PW_UNIT_TEST_LINK_FILE_CONTAINING_TEST(NotARealSuite, NotARealTest); 50 51 #elif 0 52 53 PW_UNIT_TEST_LINK_FILE_CONTAINING_TEST(StaticLibraryArchivedTest, NotARealTest); 54 55 #endif // negative linking tests 56 57 } // namespace pw::unit_test 58