blob: bcd4194ec064fb8f8f7548b61c39c9fa53ce8dc0 [file] [log] [blame]
Rich Lanea06d0c32013-03-25 08:52:03 -07001:: # Copyright 2013, Big Switch Networks, Inc.
2:: #
3:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4:: # the following special exception:
5:: #
6:: # LOXI Exception
7:: #
8:: # As a special exception to the terms of the EPL, you may distribute libraries
9:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
11:: # from the LoxiGen Libraries and the notice provided below is (i) included in
12:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13:: # documentation for the LoxiGen Libraries, if distributed in binary form.
14:: #
15:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16:: #
17:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18:: # a copy of the EPL at:
19:: #
20:: # http://www.eclipse.org/legal/epl-v10.html
21:: #
22:: # Unless required by applicable law or agreed to in writing, software
23:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25:: # EPL for the specific language governing permissions and limitations
26:: # under the EPL.
27::
Rich Laned983aa52013-06-13 11:48:37 -070028:: include('_copyright.c')
Rich Lanea06d0c32013-03-25 08:52:03 -070029
30/**
31 *
32 * Test utility functions
33 *
34 */
35
36#include <locitest/test_common.h>
37#include <loci/of_utils.h>
38
39/**
40 * Test has output port utility function
41 */
42int
43test_has_outport(void)
44{
45 of_list_action_t *list;
46 of_action_t elt;
47 of_action_set_dl_src_t *set_dl_src;
48 of_action_output_t *output;
49
50 set_dl_src = &elt.set_dl_src;
51 output = &elt.output;
52
53 list = of_list_action_new(OF_VERSION_1_0);
54 TEST_ASSERT(list != NULL);
55
56 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
57 TEST_ASSERT(!of_action_list_has_out_port(list, 1));
58
59 /* Add some other action */
60 of_action_set_dl_src_init(set_dl_src, OF_VERSION_1_0, -1, 1);
61 TEST_OK(of_list_action_append_bind(list, (of_action_t *)set_dl_src));
62
63 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
64 TEST_ASSERT(!of_action_list_has_out_port(list, 1));
65
66 /* Add port 2 */
67 of_action_output_init(output, OF_VERSION_1_0, -1, 1);
68 TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
69 of_action_output_port_set(output, 2);
70
71 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
72 TEST_ASSERT(!of_action_list_has_out_port(list, 1));
73 TEST_ASSERT(of_action_list_has_out_port(list, 2));
74
75 /* Add port 1 */
76 of_action_output_init(output, OF_VERSION_1_0, -1, 1);
77 TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
78 of_action_output_port_set(output, 1);
79
80 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
81 TEST_ASSERT(of_action_list_has_out_port(list, 1));
82 TEST_ASSERT(of_action_list_has_out_port(list, 2));
83
84 /* Start over and put action at front of list */
85 of_list_action_delete(list);
86
87 list = of_list_action_new(OF_VERSION_1_0);
88 TEST_ASSERT(list != NULL);
89
90 /* Add port 2 */
91 of_action_output_init(output, OF_VERSION_1_0, -1, 1);
92 TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
93 of_action_output_port_set(output, 2);
94
95 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
96 TEST_ASSERT(!of_action_list_has_out_port(list, 1));
97 TEST_ASSERT(of_action_list_has_out_port(list, 2));
98
99 /* Add some other action */
100 of_action_set_dl_src_init(set_dl_src, OF_VERSION_1_0, -1, 1);
101 TEST_OK(of_list_action_append_bind(list, (of_action_t *)set_dl_src));
102
103 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
104 TEST_ASSERT(!of_action_list_has_out_port(list, 1));
105 TEST_ASSERT(of_action_list_has_out_port(list, 2));
106
107 /* Add port 1 */
108 of_action_output_init(output, OF_VERSION_1_0, -1, 1);
109 TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
110 of_action_output_port_set(output, 1);
111
112 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
113 TEST_ASSERT(of_action_list_has_out_port(list, 1));
114 TEST_ASSERT(of_action_list_has_out_port(list, 2));
115
116 of_list_action_delete(list);
117
118 return TEST_PASS;
119}
120
121int
122run_utility_tests(void)
123{
124 RUN_TEST(has_outport);
125 RUN_TEST(dump_objs);
126
127 return TEST_PASS;
128}