gusimplewhiteboard
SimpleWhiteboardTestPlainC.m
Go to the documentation of this file.
1/*
2 * SimpleWhiteboardTestPlainC.m
3 *
4 * Created by Rene Hexel on 18/06/2014.
5 * Copyright (c) 2014, 2018 Rene Hexel.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgement:
22 *
23 * This product includes software developed by Rene Hexel.
24 *
25 * 4. Neither the name of the author nor the names of contributors
26 * may be used to endorse or promote products derived from this
27 * software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * -----------------------------------------------------------------------
42 * This program is free software; you can redistribute it and/or
43 * modify it under the above terms or under the terms of the GNU
44 * General Public License as published by the Free Software Foundation;
45 * either version 2 of the License, or (at your option) any later version.
46 *
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
51 *
52 * You should have received a copy of the GNU General Public License
53 * along with this program; if not, see http://www.gnu.org/licenses/
54 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
55 * Fifth Floor, Boston, MA 02110-1301, USA.
56 *
57 */
58#import <XCTest/XCTest.h>
59#include "gusimplewhiteboard.h"
61
62#include "wb_point2d.h"
68
69static const int16_t test_x = 1, test_y = 2, test_z = 42;
70
72@interface SimpleWhiteboardTestPlainC: XCTestCase
73@property (nonatomic, assign) gu_simple_whiteboard_descriptor *wbd;
74@property (nonatomic, assign) gu_simple_whiteboard *wb;
75@end
76
77@implementation SimpleWhiteboardTestPlainC
78
79- (void) setUp
80{
81 [super setUp];
82 if ((_wbd = get_local_singleton_whiteboard()))
83 _wb = _wbd->wb;
84}
85
86- (void) tearDown
87{
88 _wbd = NULL;
89}
90
91
93{
94 struct wb_vision_control_status my_variable;
95 strcpy(my_variable.colourCalibration,"test");
96 int result = strcmp(my_variable.colourCalibration,"test");
97 XCTAssertEqual(result,0);
98
99}
100
102{
103 XCTAssertNotEqual(_wbd, NULL, @"Whoa, got a NULL singleton Whiteboard");
104 XCTAssertNotEqual(_wb, NULL, @"Whoa, got a NULL underlying Whiteboard");
105}
106
107
108- (void) testPostPoint2D
109{
110 struct wb_point2d point = { test_x, test_y };
111 gu_simple_message *m = gsw_next_message(_wb, 0); // using reserved type
112 struct wb_point2d *wbpoint = (struct wb_point2d *) m;
113 *wbpoint = point;
114 gsw_increment(_wb, 0);
116
117 XCTAssertEqual(point.x, wbpoint->x, @"Got differing x on wb");
118 XCTAssertEqual(point.y, wbpoint->y, @"Got differing y on wb");
119}
120
121
122- (void) testGetPoint2D
123{
124 [self testPostPoint2D];
125
127 struct wb_point2d *wbpoint = (struct wb_point2d *) m;
128
129 XCTAssertEqual(test_x, wbpoint->x, @"Got differing x from wb");
130 XCTAssertEqual(test_y, wbpoint->y, @"Got differing y from wb");
131}
132
133
134//- (void) testPostPoint3D
135//{
136// struct wb_point3d point = { test_x, test_y, test_z };
137// gu_simple_message *m = gsw_next_message(_wb, 0); // using reserved type
138// struct wb_point3d *wbpoint = (struct wb_point3d *) m;
139// *wbpoint = point;
140// gsw_increment(_wb, 0);
141// gsw_increment_event_counter(_wb, 0);
142//
143// XCTAssertEqual(point.x, wbpoint->x, @"Got differing x on wb");
144// XCTAssertEqual(point.y, wbpoint->y, @"Got differing y on wb");
145// XCTAssertEqual(point.z, wbpoint->z, @"Got differing z on wb");
146//}
147
148
149//- (void) testGetPoint3D
150//{
151// [self testPostPoint3D];
152//
153// gu_simple_message *m = gsw_current_message(_wb, 0);
154// struct wb_point3d *wbpoint = (struct wb_point3d *) m;
155//
156// XCTAssertEqual(test_x, wbpoint->x, @"Got differing x from wb");
157// XCTAssertEqual(test_y, wbpoint->y, @"Got differing y from wb");
158// XCTAssertEqual(test_z, wbpoint->z, @"Got differing z from wb");
159//}
160
161@end
gu_simple_message * gsw_next_message(gu_simple_whiteboard *wb, int i)
get the next shared memory location for the given whiteboard message type i
void gsw_increment(gu_simple_whiteboard *wb, int i)
get the next shared memory location for the given whiteboard message type i
void gsw_increment_event_counter(gu_simple_whiteboard *wb, int i)
add to a messages event counter on the wb
gu_simple_whiteboard_descriptor * get_local_singleton_whiteboard(void)
create a simple whiteboard for the local singleton wb pointer
gu_simple_message * gsw_current_message(gu_simple_whiteboard *wb, int i)
get the current shared memory location for the given whiteboard message type i
plain c code testing of the simple whiteboard implementation
gu_simple_whiteboard_descriptor * wbd
wb pointer
gu_simple_whiteboard * wb
wb class pointer
the actual whiteboard in shared mem
the underlying whiteboard object
WHITEBOARD_POSTER_STRING_CONVERSION.
Definition: wb_point2d.h:105
int16_t y
y
Definition: wb_point2d.h:115
int16_t x
x
Definition: wb_point2d.h:110
WHITEBOARD_POSTER_STRING_CONVERSION.
union type that is used to store data in shared memory
gusimplewhiteboard
gusimplewhiteboard