]> git.donarmstrong.com Git - lilypond.git/commitdiff
Yaffut update.
authorJan Nieuwenhuizen <janneke@gnu.org>
Wed, 14 Feb 2007 10:58:25 +0000 (11:58 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Wed, 14 Feb 2007 10:58:25 +0000 (11:58 +0100)
flower/include/file-name.hh
flower/include/yaffut-parameters.hh
flower/include/yaffut.hh
flower/test-file-name.cc

index 46d4724974e5da7f1c36724ded27bcb7009c88bc..e8ea1ea3c2d67667c535f5ad51b87d07ad9b72df 100644 (file)
@@ -23,7 +23,7 @@ public:
   string base_;
   string ext_;
 
-  File_name (string);
+  File_name (string="");
 
   bool is_absolute () const;
   string to_string () const;
index 9a569f903ca45a7ac73d5de938b196e38ea6d015..57429e64baa362c380a7eda4c3e10a75cc71654a 100644 (file)
@@ -3,28 +3,17 @@
 
 #include "yaffut.hh"
 
-namespace yaffut {
-template <typename Suite, typename ParameterOne, typename Case>
-struct TestOne: public ITest, public Suite
-{
-  ParameterOne const parameter_one_;
-  //static Registrator<Suite, Case> s_Registrator;
-  TestOne(ParameterOne p)
-  : Suite(p)
-  , parameter_one_ (p)
-  {
-    Registrator<Suite, Case>* r = &Test<Suite, Case>::s_Registrator;
-    r = 0;
-  }
-};
-
-#define TEST_STRING(Suite, Case, String)\
+#define TEST_PARAMETER(Suite, Case, Type, value) \
   namespace { \
-      struct Case: public yaffut::TestOne<Suite, std::string, Case>{ Case(); };        \
+    struct Case: public yaffut::Test<Suite, Case>{ \
+       Type parameter_one_; \
+        Case (); \
+    }; \
   } \
-  template struct yaffut::TestOne<Suite, std::string, Case>; Case::Case() \
-    : yaffut::TestOne<Suite, std::string, Case> (String)
+template struct yaffut::Test<Suite, Case>; Case::Case () \
+  : Suite (value), parameter_one_ (value)
 
-}
+#define TEST_STRING(Suite, Case, String) \
+  TEST_PARAMETER(Suite, Case, std::string, String)
 
 #endif // __YAFFUT_PARAMETERS_H__
index 91a35214935e1598a873a1e6fdc6af0397f2c01b..06434b03324ad0b334b318065014cb95a4d1cbd7 100644 (file)
@@ -135,12 +135,12 @@ public:
         }
         catch(const std::exception& e)
         {
-          std::cout << "[FAIL]\n" << e.what() << std::flush;
+          std::cout << "[FAIL]\n  " << e.what() << std::flush;
           ++m_fail;
         }
         catch(...)
         {
-          std::cout << "[FAIL]\nunknown exception" << std::flush;
+          std::cout << "[FAIL]\n  unknown exception" << std::flush;
           ++m_fail;
         }
       }
@@ -241,12 +241,30 @@ struct Registrator
   }
 };
 
-template <typename Suite, typename Case>
-struct Test: public ITest, public Suite
+template <typename Case>
+struct Registrator<Case, void>
+{
+  Registrator()
+  {
+    Factory::Instance().Register(TestName(), Create);
+  }
+  const std::string& TestName()
+  {
+    static const std::string name ("::" + demangle<Case>());
+    return name;
+  }
+  static ITest* Create()
+  {
+    return new Case;
+  }
+};
+
+
+template <typename Suite, typename Case = void>
+struct Test: public ITest, public virtual Suite
 {
   static Registrator<Suite, Case> s_Registrator;
-  Test()
-  : Suite()
+  Test(): Suite()
   {
     Registrator<Suite, Case>* r = &s_Registrator;
     r = 0;
@@ -266,6 +284,33 @@ struct Test: public ITest, public Suite
 template <typename Suite, typename Case>
 Registrator<Suite, Case> Test<Suite, Case>::s_Registrator;
 
+
+template <typename Case>
+struct Test<Case, void>: public ITest
+{
+  static Registrator<Case, void> s_Registrator;
+  Test()
+  {
+    Registrator<Case, void>* r = &s_Registrator;
+    r = 0;
+  }
+  template <typename E, typename T>
+  void assert_throw(void(T::*mf)(), const char* at)
+  {
+    try
+    {
+      (dynamic_cast<T*> (this)->*mf)();
+      throw yaffut::failure (at, "statement failed to throw");
+    }
+    catch(const E&){}
+  }
+};
+
+template <typename Case>
+Registrator<Case, void> Test<Case, void>::s_Registrator;
+
+
+
 template <typename Expected, typename Actual>
 void equal(const Expected& e, const Actual& a, const char* at = "", const char* expr = "")
 {
@@ -328,19 +373,16 @@ void assert_throw(void(*pf)(), const char* at = "")
   catch(const E&){}
 }
 
-//define catch-all suite
-struct Suite {};
-
 }
 
-//and for those who prefer macro obscurity over more typing
+//and for those who prefer macro obscurity over typing
 #define TEST(Suite, Case)\
   namespace { struct Case: public yaffut::Test<Suite, Case>{ Case(); }; } \
   template struct yaffut::Test<Suite, Case>; Case::Case()
 
 #define FUNC(Case)\
-  namespace { struct Case: public yaffut::Test<yaffut::Suite, Case>{ Case(); }; } \
-  template struct yaffut::Test<yaffut::Suite, Case>; Case::Case()
+  namespace { struct Case: public yaffut::Test<Case>{ Case(); }; } \
+  template struct yaffut::Test<Case>; Case::Case()
 
 #ifdef YAFFUT_MAIN
 
index 0bd427bda829afd73a680c04895027256aeceb20..edae635e822e618d37a18f5fe92433109180091a 100644 (file)
@@ -6,6 +6,11 @@ using namespace std;
 
 string slashify (string file_name);
 
+struct CaseB: public yaffut::Test<File_name, CaseB>
+{
+  CaseB(): File_name("123"){}
+};
+
 TEST_STRING (File_name, Mingw_slashify, "foe.ly")
 {
   string s = slashify (to_string ());