r24872: Use torture API a bit more
[kai/samba.git] / source4 / torture / ui.h
index f0628b77587e6b30cf942d6ffbeacf34394c4e03..71c21223159045bc36cbd89879d2090a436779cb 100644 (file)
@@ -6,7 +6,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -15,8 +15,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef __TORTURE_UI_H__
@@ -40,7 +39,9 @@ enum torture_result {
  */
 struct torture_ui_ops
 {
+       void (*init) (struct torture_context *);
        void (*comment) (struct torture_context *, const char *);
+       void (*warning) (struct torture_context *, const char *);
        void (*suite_start) (struct torture_context *, struct torture_suite *);
        void (*suite_finish) (struct torture_context *, struct torture_suite *);
        void (*tcase_start) (struct torture_context *, struct torture_tcase *); 
@@ -75,22 +76,20 @@ struct torture_context
        const struct torture_ui_ops *ui_ops;
        void *ui_data;
 
+       char *active_testname;
        struct torture_test *active_test;
        struct torture_tcase *active_tcase;
 
-       int skipped;
-       int todo;
-       int success;
-       int failed;
-       int errors;
-
        bool quiet; /* Whether tests should avoid writing output to stdout */
 
        enum torture_result last_result;
        char *last_reason;
 
-       char *outputdir;
+       bool returncode;
+
+       const char *outputdir;
        int level;
+       struct event_context *ev;
 };
 
 /* 
@@ -130,7 +129,6 @@ struct torture_tcase {
 struct torture_suite
 {
        const char *name;
-       const char *path; /* Used by subunit tests only */
        const char *description;
        struct torture_tcase *testcases;
        struct torture_suite *children;
@@ -167,6 +165,13 @@ struct torture_tcase *torture_suite_add_simple_tcase(
                bool (*run) (struct torture_context *test, const void *test_data),
                const void *data);
 
+/* Convenience function that adds a test which only 
+ * gets the test case data */
+struct torture_test *torture_tcase_add_simple_test(
+               struct torture_tcase *tcase,
+               const char *name,
+               bool (*run) (struct torture_context *test, const void *tcase_data));
+
 /* Convenience wrapper that adds a test that doesn't need any 
  * testcase data */
 struct torture_tcase *torture_suite_add_simple_test(
@@ -192,6 +197,7 @@ bool torture_run_test(struct torture_context *context,
                                          struct torture_test *test);
 
 void torture_comment(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
+void torture_warning(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
 void torture_result(struct torture_context *test, 
                        enum torture_result, const char *reason, ...) PRINTF_ATTRIBUTE(3,4);
 
@@ -236,12 +242,59 @@ void torture_result(struct torture_context *test,
        } \
        } while(0)
 
+#define torture_assert_file_contains_text(torture_ctx,filename,expected,cmt)\
+       do { \
+       char *__got; \
+       const char *__expected = (expected); \
+       size_t __size; \
+       __got = file_load(filename, &__size, torture_ctx); \
+       if (__got == NULL) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                              __location__": unable to open %s: %s\n", \
+                              filename, cmt); \
+               return false; \
+       } \
+       \
+       if (strcmp_safe(__got, __expected) != 0) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": %s contained:\n%sExpected: %s%s\n", \
+                       filename, __got, __expected, cmt); \
+               talloc_free(__got); \
+               return false; \
+       } \
+       talloc_free(__got); \
+       } while(0)
+
+#define torture_assert_file_contains(torture_ctx,filename,expected,cmt)\
+       do { const char *__got, *__expected = (expected); \
+       size_t __size; \
+       __got = file_load(filename, *size, torture_ctx); \
+       if (strcmp_safe(__got, __expected) != 0) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                                          __location__": %s contained:\n%sExpected: %s%s\n", \
+                                          __got, __expected, cmt); \
+               talloc_free(__got); \
+               return false; \
+       } \
+       talloc_free(__got); \
+       } while(0)
+
 #define torture_assert_int_equal(torture_ctx,got,expected,cmt)\
        do { int __got = (got), __expected = (expected); \
        if (__got != __expected) { \
                torture_result(torture_ctx, TORTURE_FAIL, \
-                                        __location__": "#got" was %d, expected %d: %s", \
-                                          __got, __expected, cmt); \
+                       __location__": "#got" was %d, expected %d: %s", \
+                       __got, __expected, cmt); \
+               return false; \
+       } \
+       } while(0)
+
+#define torture_assert_u64_equal(torture_ctx,got,expected,cmt)\
+       do { uint64_t __got = (got), __expected = (expected); \
+       if (__got != __expected) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was %llu, expected %llu: %s", \
+                       (unsigned long long)__got, (unsigned long long)__expected, cmt); \
                return false; \
        } \
        } while(0)
@@ -267,6 +320,10 @@ void torture_result(struct torture_context *test,
                torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
                return false; \
        } while (0)
+#define torture_fail_goto(torture_ctx,label,cmt) do {\
+               torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
+               goto label; \
+       } while (0)
 
 #define torture_out stderr
 
@@ -286,6 +343,10 @@ int torture_setting_int(struct torture_context *test,
                                                const char *name, 
                                                int default_value);
 
+double torture_setting_double(struct torture_context *test, 
+                                               const char *name, 
+                                               double default_value);
+
 bool torture_setting_bool(struct torture_context *test, 
                                                  const char *name, 
                                                  bool default_value);