]> rtime.felk.cvut.cz Git - wvtest.git/blob - dotnet/wvtest.t.cs
6fd3c46d4394c31cf476af2f80183bcddfe64d7a
[wvtest.git] / dotnet / wvtest.t.cs
1 /*
2  * Versaplex:
3  *   Copyright (C)2007-2008 Versabanq Innovations Inc. and contributors.
4  *       See the included file named LICENSE for license information.
5  */
6 #include "wvtest.cs.h"
7 using System;
8 using Wv.Test;
9
10 [TestFixture]
11 public class WvTestTest
12 {
13         [Test] public void test_wvtest()
14         {
15             WVPASS(1);
16             WVPASS("hello");
17             WVPASS(new Object());
18             WVPASS(0 != 1);
19             
20             WVFAIL(0);
21             WVFAIL("");
22             WVFAIL(null);
23             
24             WVPASSEQ(7, 7);
25             WVPASSEQ("foo", "foo");
26             WVPASSEQ("", "");
27             Object obj = new Object();
28             WVPASSEQ(obj, obj);
29             WVPASSEQ(null, null);
30             
31             WVPASSNE(7, 8);
32             WVPASSNE("foo", "blue");
33             WVPASSNE("", "notempty");
34             WVPASSNE(null, "");
35             WVPASSNE(obj, null);
36             WVPASSNE(obj, new Object());
37             WVPASSNE(new Object(), new Object());
38         }   
39     
40         // these are only public to get rid of the "not assigned to" warnings.
41         // we don't assign to them because that's the whole point of the test.
42         public DateTime null_date;
43         public TimeSpan null_span;
44         
45         [Test] public void test_dates_and_spans()
46         {
47             WVPASS(null_date == DateTime.MinValue);
48             WVPASSEQ(null_date, DateTime.MinValue);
49             WVPASS(null_span == TimeSpan.Zero);
50             WVPASSEQ(null_span, TimeSpan.Zero);
51             
52             TimeSpan t = TimeSpan.FromMinutes(60*24*7);
53             WVPASSEQ(t.ToString(), "7.00:00:00");
54             WVPASSEQ(t.Ticks, 7*24*60*60*10000000L);
55             WVPASS(t.TotalMinutes == 7*24*60);
56             WVPASSEQ(t.TotalMinutes, 7*24*60);
57             WVPASSEQ(t.TotalSeconds, 7*24*60*60);
58             WVPASSEQ(t.Minutes, 0);
59         }
60
61         void throw_exception()
62         {
63             throw new System.Exception("Exception thrown");
64         }
65         void no_throw_exception()
66         {
67             return;
68         }
69
70         [Test] public void test_exceptions()
71         {
72             bool caught = false;
73
74             try {
75                 WVEXCEPT(throw_exception());
76             } catch (Wv.Test.WvAssertionFailure e) {
77                 throw e;
78             } catch (System.Exception) {
79                 caught = true;
80             }
81
82             WVPASS(caught);
83
84             caught = false;
85
86             System.Console.WriteLine("Ignore next failure: it is expected");
87             WvTest.expect_next_failure();
88             try {
89                 WVEXCEPT(no_throw_exception());
90             } catch (Wv.Test.WvAssertionFailure) {
91                 caught = true;
92             }
93
94             WVPASS(caught);
95         }
96 }