summaryrefslogtreecommitdiff
path: root/examples/ExampleTest.cc
blob: aebe7124b9082256f33ab9a084b884a84277209c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <uunit.h>
#include <iostream>

#include "getbaud.h"

std::ostream& operator<<(std::ostream& stream, const Speed& speed)
{
	switch(speed)
	{
	case Speed::B0: stream << "Speed::B0"; break;
	case Speed::B50: stream << "Speed::B50"; break;
	case Speed::B75: stream << "Speed::B75"; break;
	case Speed::B110: stream << "Speed::B110"; break;
	case Speed::B134: stream << "Speed::B134"; break;
	case Speed::B150: stream << "Speed::B150"; break;
	case Speed::B200: stream << "Speed::B200"; break;
	case Speed::B300: stream << "Speed::B300"; break;
	case Speed::B600: stream << "Speed::B600"; break;
	case Speed::B1200: stream << "Speed::B1200"; break;
	case Speed::B1800: stream << "Speed::B1800"; break;
	case Speed::B2400: stream << "Speed::B2400"; break;
	case Speed::B4800: stream << "Speed::B4800"; break;
	case Speed::B9600: stream << "Speed::B9600"; break;
	case Speed::B19200: stream << "Speed::B19200"; break;
	case Speed::B38400: stream << "Speed::B38400"; break;
	case Speed::B57600: stream << "Speed::B57600"; break;
	case Speed::B115200: stream << "Speed::B115200"; break;
	case Speed::B230400: stream << "Speed::B230400"; break;
	}
	return stream;
}

class ExampleTest
	: public uUnit
{
public:
	ExampleTest()
	{
		uTEST(ExampleTest::boundaryTests);
		uTEST(ExampleTest::exceptionTests);
	}

	void boundaryTests()
	{
		uASSERT_EQUAL(Speed::B0, getBaud(0));
		uASSERT_EQUAL(Speed::B0, getBaud(1));
		uASSERT_EQUAL(Speed::B0, getBaud(49));

		uASSERT_EQUAL(Speed::B50, getBaud(50));
		uASSERT_EQUAL(Speed::B50, getBaud(51));
		uASSERT_EQUAL(Speed::B50, getBaud(74));

		uASSERT_EQUAL(Speed::B75, getBaud(75));
		uASSERT_EQUAL(Speed::B75, getBaud(76));
		uASSERT_EQUAL(Speed::B75, getBaud(109));

		uASSERT_EQUAL(Speed::B110, getBaud(110));
		uASSERT_EQUAL(Speed::B110, getBaud(111));
		uASSERT_EQUAL(Speed::B110, getBaud(133));

		uASSERT_EQUAL(Speed::B134, getBaud(134));
		uASSERT_EQUAL(Speed::B134, getBaud(135));
		uASSERT_EQUAL(Speed::B134, getBaud(149));

		uASSERT_EQUAL(Speed::B150, getBaud(150));
		uASSERT_EQUAL(Speed::B150, getBaud(151));
		uASSERT_EQUAL(Speed::B150, getBaud(199));

		uASSERT_EQUAL(Speed::B200, getBaud(200));
		uASSERT_EQUAL(Speed::B200, getBaud(201));
		uASSERT_EQUAL(Speed::B200, getBaud(299));

		uASSERT_EQUAL(Speed::B300, getBaud(300));
		uASSERT_EQUAL(Speed::B300, getBaud(301));
		uASSERT_EQUAL(Speed::B300, getBaud(599));

		uASSERT_EQUAL(Speed::B600, getBaud(600));
		uASSERT_EQUAL(Speed::B600, getBaud(601));
		uASSERT_EQUAL(Speed::B600, getBaud(1199));

		uASSERT_EQUAL(Speed::B1200, getBaud(1200));
		uASSERT_EQUAL(Speed::B1200, getBaud(1201));
		uASSERT_EQUAL(Speed::B1200, getBaud(1799));

		uASSERT_EQUAL(Speed::B1800, getBaud(1800));
		uASSERT_EQUAL(Speed::B1800, getBaud(1801));
		uASSERT_EQUAL(Speed::B1800, getBaud(2399));

		uASSERT_EQUAL(Speed::B2400, getBaud(2400));
		uASSERT_EQUAL(Speed::B2400, getBaud(2401));
		uASSERT_EQUAL(Speed::B2400, getBaud(4799));

		uASSERT_EQUAL(Speed::B4800, getBaud(4800));
		uASSERT_EQUAL(Speed::B4800, getBaud(4801));
		uASSERT_EQUAL(Speed::B4800, getBaud(9599));

		uASSERT_EQUAL(Speed::B9600, getBaud(9600));
		uASSERT_EQUAL(Speed::B9600, getBaud(9601));
		uASSERT_EQUAL(Speed::B9600, getBaud(19199));

		uASSERT_EQUAL(Speed::B19200, getBaud(19200));
		uASSERT_EQUAL(Speed::B19200, getBaud(19201));
		uASSERT_EQUAL(Speed::B19200, getBaud(38399));

		uASSERT_EQUAL(Speed::B38400, getBaud(38400));
		uASSERT_EQUAL(Speed::B38400, getBaud(38401));
		uASSERT_EQUAL(Speed::B38400, getBaud(57599));

		uASSERT_EQUAL(Speed::B57600, getBaud(57600));
		uASSERT_EQUAL(Speed::B57600, getBaud(57601));
		uASSERT_EQUAL(Speed::B57600, getBaud(115199));

		uASSERT_EQUAL(Speed::B115200, getBaud(115200));
		uASSERT_EQUAL(Speed::B115200, getBaud(115201));
		uASSERT_EQUAL(Speed::B115200, getBaud(230399));

		uASSERT_EQUAL(Speed::B230400, getBaud(230400));
		uASSERT_EQUAL(Speed::B230400, getBaud(230401));
	}

	void exceptionTests()
	{
		uASSERT_THROWS(bad_speed, getBaud(-1));
	}
};

// Registers the fixture into the 'registry'
static ExampleTest test;