{"id":19109,"date":"2025-08-29T09:48:18","date_gmt":"2025-08-29T09:48:18","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=19109"},"modified":"2025-08-29T10:09:20","modified_gmt":"2025-08-29T10:09:20","slug":"testing-templates-gtest","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=19109","title":{"rendered":"Testing templates (gtest)"},"content":{"rendered":"<pre class=\"brush: cpp; gutter: false; title: ; notranslate\" title=\"\">\r\n#include &lt;gtest\/gtest.h&gt;\r\n#include &lt;concepts&gt;\r\n#include &lt;string&gt;\r\n\r\ntemplate &lt;typename T&gt;\r\nconcept Animal = requires(T a) {\r\n    { a.eats() } -&gt; std::same_as&lt;std::string&gt;;\r\n};\r\n\r\nstruct GrassEater {\r\n    std::string eats() const { return &quot;grass&quot;; }\r\n};\r\nstruct Cow : public GrassEater {};\r\nstruct Duck : public GrassEater {};\r\n\r\ntemplate &lt;Animal T&gt;\r\nclass GrassEaterTest : public ::testing::Test {\r\npublic:\r\n    T grass_eater;\r\n};\r\n\r\ntypedef ::testing::Types&lt;Cow, Duck&gt; GrassEaterTypes;\r\nTYPED_TEST_SUITE(GrassEaterTest, GrassEaterTypes);\r\n\r\nTYPED_TEST(GrassEaterTest, EatsGrass) {\r\n    EXPECT_EQ(this-&gt;grass_eater.eats(), &quot;grass&quot;);\r\n}\r\n<\/pre>\n<pre>\r\n$ apt install libgtest-dev\r\n$ clang++ main.cpp --std=c++23 -lgtest -lgtest_main -pthread\r\n$ .\/a.out\r\n[==========] Running 2 tests from 2 test suites.\r\n[----------] Global test environment set-up.\r\n[----------] 1 test from GrassEaterTest\/0, where TypeParam = Cow\r\n[ RUN      ] GrassEaterTest\/0.EatsGrass\r\n[       OK ] GrassEaterTest\/0.EatsGrass (0 ms)\r\n[----------] 1 test from GrassEaterTest\/0 (0 ms total)\r\n\r\n[----------] 1 test from GrassEaterTest\/1, where TypeParam = Duck\r\n[ RUN      ] GrassEaterTest\/1.EatsGrass\r\n[       OK ] GrassEaterTest\/1.EatsGrass (0 ms)\r\n[----------] 1 test from GrassEaterTest\/1 (0 ms total)\r\n\r\n[----------] Global test environment tear-down\r\n[==========] 2 tests from 2 test suites ran. (0 ms total)\r\n[  PASSED  ] 2 tests.\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>$ apt install libgtest-dev $ clang++ main.cpp &#8211;std=c++23 -lgtest -lgtest_main -pthread $ .\/a.out [==========] Running 2 tests from 2 test<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[27],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/19109"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19109"}],"version-history":[{"count":7,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/19109\/revisions"}],"predecessor-version":[{"id":19116,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/19109\/revisions\/19116"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19109"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}