concepts.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Includes
00011 *****************************************************************************/
00012 
00013 #include <iostream>
00014 #include <gtest/gtest.h>
00015 #include <vector>
00016 #include "../../include/ecl/concepts/blueprints.hpp"
00017 #include "../../include/ecl/concepts/containers.hpp"
00018 #include "../../include/ecl/concepts/macros.hpp"
00019 #include "../../include/ecl/concepts/streams.hpp"
00020 
00025 /*****************************************************************************
00026 ** Classes
00027 *****************************************************************************/
00028 
00029 namespace ecl {
00030 namespace concepts {
00031 namespace tests {
00032 
00033 template <typename T>
00034 class Concept {
00035     public:
00036                 ecl_compile_time_concept_test(Concept)
00037         {
00038             T t;
00039             t.apply();  // This is the characteristic function required by this concept.
00040         }
00041 };
00042 
00043 class A {
00044     public:
00045         void apply() {}; // Comment this line to cause the compile to fail.
00046 };
00047 
00048 class BluePrintCandidate {
00049 public:
00050         typedef int base_type;
00051         base_type instantiate();
00052         void apply(base_type dude);
00053 };
00054 
00055 } // namespace tests
00056 } // namespace concepts
00057 } // namespace ecl
00058 
00059 /*****************************************************************************
00060 ** Tests
00061 *****************************************************************************/
00062 
00063 using namespace ecl::concepts::tests;
00064 
00065 // By default, the concept tests will pass. To cause it to fail
00066 // comment the concept test functions and rebuild.
00067 
00068 
00069 TEST(CompileTimeTests,macro) {
00070         ecl_compile_time_concept_check(Concept<A>);
00071         EXPECT_TRUE(true); // Should only fall over if compile time check is triggered.
00072 }
00073 
00074 TEST(CompileTimeTests,stream) {
00075         ecl_compile_time_concept_check(ecl::StreamConcept<std::ostream>);
00076         EXPECT_TRUE(true); // Should only fall over if compile time check is triggered.
00077 }
00078 
00079 TEST(CompileTimeTests,blueprint) {
00080         ecl_compile_time_concept_check(ecl::BluePrintConcept<BluePrintCandidate>);
00081         EXPECT_TRUE(true); // Should only fall over if compile time check is triggered.
00082 }
00083 
00084 TEST(CompileTimeTests,container) {
00085         ecl_compile_time_concept_check(ecl::DynamicContainerConcept< std::vector<int> >);
00086         EXPECT_TRUE(true); // Should only fall over if compile time check is triggered.
00087 }
00088 
00089 /*****************************************************************************
00090 ** Main
00091 *****************************************************************************/
00092 
00093 int main(int argc, char **argv) {
00094 
00095     testing::InitGoogleTest(&argc,argv);
00096     return RUN_ALL_TESTS();
00097 }
00098 


ecl_concepts
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:12:03