Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/test/events/event_factory_test.cppGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 #include <gtest/gtest.h> 00035 #include <vector> 00036 #include <string> 00037 00038 #include "../src/recognition/events/event_factory.h" 00039 00043 TEST(EventFactoryTestSuite, testCompleted) 00044 { 00045 Event event = EventFactory::completed(); 00046 Event completed = CompletedEvent(); 00047 00048 EXPECT_TRUE(EventFactory::isCompleted(event)); 00049 EXPECT_EQ(event.getName(), completed.getName()); 00050 EXPECT_EQ(EventFactory::getCompletedName(), event.getName()); 00051 EXPECT_EQ((unsigned)0, event.getAdditional().size()); 00052 EXPECT_EQ(event.getAdditional().size(), completed.getAdditional().size()); 00053 00054 std::vector<std::string> additional = std::vector<std::string>(); 00055 additional.push_back("red"); 00056 additional.push_back("blue"); 00057 additional.push_back("green"); 00058 00059 event = EventFactory::completed(additional); 00060 completed = CompletedEvent(additional); 00061 00062 EXPECT_TRUE(EventFactory::isCompleted(event)); 00063 EXPECT_EQ(event.getName(), completed.getName()); 00064 EXPECT_EQ(EventFactory::getCompletedName(), event.getName()); 00065 EXPECT_EQ(additional.size(), event.getAdditional().size()); 00066 EXPECT_EQ(event.getAdditional().size(), completed.getAdditional().size()); 00067 00068 // Make sure all the objects are equal 00069 for (unsigned c = 0; c < additional.size(); c++) 00070 EXPECT_EQ(additional.at(c), event.getAdditional().at(c)); 00071 00072 // Make sure all the objects are equal between completed and created 00073 for (unsigned c = 0; c < event.getAdditional().size(); c++) 00074 EXPECT_EQ(event.getAdditional().at(c), completed.getAdditional().at(c)); 00075 } 00076 00080 TEST(EventFactoryTestSuite, testCycle) 00081 { 00082 Event event = EventFactory::cycle(); 00083 Event cycle = CycleEvent(); 00084 00085 EXPECT_TRUE(EventFactory::isCycle(event)); 00086 EXPECT_EQ(event.getName(), cycle.getName()); 00087 EXPECT_EQ(EventFactory::getCycleName(), event.getName()); 00088 EXPECT_EQ((unsigned)0, event.getAdditional().size()); 00089 EXPECT_EQ(event.getAdditional().size(), cycle.getAdditional().size()); 00090 00091 std::vector<std::string> additional = std::vector<std::string>(); 00092 additional.push_back("red"); 00093 additional.push_back("blue"); 00094 additional.push_back("green"); 00095 00096 event = EventFactory::cycle(additional); 00097 cycle = CycleEvent(additional); 00098 00099 EXPECT_TRUE(EventFactory::isCycle(event)); 00100 EXPECT_EQ(event.getName(), cycle.getName()); 00101 EXPECT_EQ(EventFactory::getCycleName(), event.getName()); 00102 EXPECT_EQ(additional.size(), event.getAdditional().size()); 00103 EXPECT_EQ(event.getAdditional().size(), cycle.getAdditional().size()); 00104 00105 // Make sure all the objects are equal 00106 for (unsigned c = 0; c < additional.size(); c++) 00107 EXPECT_EQ(additional.at(c), event.getAdditional().at(c)); 00108 00109 // Make sure all the objects are equal between cycle and created 00110 for (unsigned c = 0; c < event.getAdditional().size(); c++) 00111 EXPECT_EQ(event.getAdditional().at(c), cycle.getAdditional().at(c)); 00112 } 00113 00117 TEST(EventFactoryTestSuite, testFailed) 00118 { 00119 Event event = EventFactory::failed(); 00120 Event failed = FailedEvent(); 00121 00122 EXPECT_TRUE(EventFactory::isFailed(event)); 00123 EXPECT_EQ(event.getName(), failed.getName()); 00124 EXPECT_EQ(EventFactory::getFailedName(), event.getName()); 00125 EXPECT_EQ((unsigned)0, event.getAdditional().size()); 00126 EXPECT_EQ(event.getAdditional().size(), failed.getAdditional().size()); 00127 00128 std::vector<std::string> additional = std::vector<std::string>(); 00129 additional.push_back("red"); 00130 additional.push_back("blue"); 00131 additional.push_back("green"); 00132 00133 event = EventFactory::failed(additional); 00134 failed = FailedEvent(additional); 00135 00136 EXPECT_TRUE(EventFactory::isFailed(event)); 00137 EXPECT_EQ(event.getName(), failed.getName()); 00138 EXPECT_EQ(EventFactory::getFailedName(), event.getName()); 00139 EXPECT_EQ(additional.size(), event.getAdditional().size()); 00140 EXPECT_EQ(event.getAdditional().size(), failed.getAdditional().size()); 00141 00142 // Make sure all the objects are equal 00143 for (unsigned c = 0; c < additional.size(); c++) 00144 EXPECT_EQ(additional.at(c), event.getAdditional().at(c)); 00145 00146 // Make sure all the objects are equal between failed and created 00147 for (unsigned c = 0; c < event.getAdditional().size(); c++) 00148 EXPECT_EQ(event.getAdditional().at(c), failed.getAdditional().at(c)); 00149 } 00150 00154 TEST(EventFactoryTestSuite, testHumanInitiated) 00155 { 00156 Event event = EventFactory::humanInitiated(); 00157 Event humanInitiated = HumanInitiatedEvent(); 00158 00159 EXPECT_TRUE(EventFactory::isHumanInitiated(event)); 00160 EXPECT_EQ(event.getName(), humanInitiated.getName()); 00161 EXPECT_EQ(EventFactory::getHumanInitiatedName(), event.getName()); 00162 EXPECT_EQ((unsigned)0, event.getAdditional().size()); 00163 EXPECT_EQ(event.getAdditional().size(), humanInitiated.getAdditional().size()); 00164 00165 std::vector<std::string> additional = std::vector<std::string>(); 00166 additional.push_back("red"); 00167 additional.push_back("blue"); 00168 additional.push_back("green"); 00169 00170 event = EventFactory::humanInitiated(additional); 00171 humanInitiated = HumanInitiatedEvent(additional); 00172 00173 EXPECT_TRUE(EventFactory::isHumanInitiated(event)); 00174 EXPECT_EQ(event.getName(), humanInitiated.getName()); 00175 EXPECT_EQ(EventFactory::getHumanInitiatedName(), event.getName()); 00176 EXPECT_EQ(additional.size(), event.getAdditional().size()); 00177 EXPECT_EQ(event.getAdditional().size(), humanInitiated.getAdditional().size()); 00178 00179 // Make sure all the objects are equal 00180 for (unsigned c = 0; c < additional.size(); c++) 00181 EXPECT_EQ(additional.at(c), event.getAdditional().at(c)); 00182 00183 // Make sure all the objects are equal between humanInitiated and created 00184 for (unsigned c = 0; c < event.getAdditional().size(); c++) 00185 EXPECT_EQ(event.getAdditional().at(c), humanInitiated.getAdditional().at(c)); 00186 } 00187 00191 TEST(EventFactoryTestSuite, testRobotInitiated) 00192 { 00193 Event event = EventFactory::robotInitiated(); 00194 Event robotInitiated = RobotInitiatedEvent(); 00195 00196 EXPECT_TRUE(EventFactory::isRobotInitiated(event)); 00197 EXPECT_EQ(event.getName(), robotInitiated.getName()); 00198 EXPECT_EQ(EventFactory::getRobotInitiatedName(), event.getName()); 00199 EXPECT_EQ((unsigned)0, event.getAdditional().size()); 00200 EXPECT_EQ(event.getAdditional().size(), robotInitiated.getAdditional().size()); 00201 00202 std::vector<std::string> additional = std::vector<std::string>(); 00203 additional.push_back("red"); 00204 additional.push_back("blue"); 00205 additional.push_back("green"); 00206 00207 event = EventFactory::robotInitiated(additional); 00208 robotInitiated = RobotInitiatedEvent(additional); 00209 00210 EXPECT_TRUE(EventFactory::isRobotInitiated(event)); 00211 EXPECT_EQ(event.getName(), robotInitiated.getName()); 00212 EXPECT_EQ(EventFactory::getRobotInitiatedName(), event.getName()); 00213 EXPECT_EQ(additional.size(), event.getAdditional().size()); 00214 EXPECT_EQ(event.getAdditional().size(), robotInitiated.getAdditional().size()); 00215 00216 // Make sure all the objects are equal 00217 for (unsigned c = 0; c < additional.size(); c++) 00218 EXPECT_EQ(additional.at(c), event.getAdditional().at(c)); 00219 00220 // Make sure all the objects are equal between robotInitiated and created 00221 for (unsigned c = 0; c < event.getAdditional().size(); c++) 00222 EXPECT_EQ(event.getAdditional().at(c), robotInitiated.getAdditional().at(c)); 00223 } 00224 00228 TEST(EventFactoryTestSuite, testSharedGaze) 00229 { 00230 Event event = EventFactory::sharedGaze(); 00231 Event sharedGaze = SharedGazeEvent(); 00232 00233 EXPECT_TRUE(EventFactory::isSharedGaze(event)); 00234 EXPECT_EQ(event.getName(), sharedGaze.getName()); 00235 EXPECT_EQ(EventFactory::getSharedGazeName(), event.getName()); 00236 EXPECT_EQ((unsigned)0, event.getAdditional().size()); 00237 EXPECT_EQ(event.getAdditional().size(), sharedGaze.getAdditional().size()); 00238 00239 std::vector<std::string> additional = std::vector<std::string>(); 00240 additional.push_back("red"); 00241 additional.push_back("blue"); 00242 additional.push_back("green"); 00243 00244 event = EventFactory::sharedGaze(additional); 00245 sharedGaze = SharedGazeEvent(additional); 00246 00247 EXPECT_TRUE(EventFactory::isSharedGaze(event)); 00248 EXPECT_EQ(event.getName(), sharedGaze.getName()); 00249 EXPECT_EQ(EventFactory::getSharedGazeName(), event.getName()); 00250 EXPECT_EQ(additional.size(), event.getAdditional().size()); 00251 EXPECT_EQ(event.getAdditional().size(), sharedGaze.getAdditional().size()); 00252 00253 // Make sure all the objects are equal 00254 for (unsigned c = 0; c < additional.size(); c++) 00255 EXPECT_EQ(additional.at(c), event.getAdditional().at(c)); 00256 00257 // Make sure all the objects are equal between sharedGaze and created 00258 for (unsigned c = 0; c < event.getAdditional().size(); c++) 00259 EXPECT_EQ(event.getAdditional().at(c), sharedGaze.getAdditional().at(c)); 00260 } 00261 00265 TEST(EventFactoryTestSuite, testSuccess) 00266 { 00267 Event event = EventFactory::success(); 00268 Event success = SuccessEvent(); 00269 00270 EXPECT_TRUE(EventFactory::isSuccess(event)); 00271 EXPECT_EQ(event.getName(), success.getName()); 00272 EXPECT_EQ(EventFactory::getSuccessName(), event.getName()); 00273 EXPECT_EQ((unsigned)0, event.getAdditional().size()); 00274 EXPECT_EQ(event.getAdditional().size(), success.getAdditional().size()); 00275 00276 std::vector<std::string> additional = std::vector<std::string>(); 00277 additional.push_back("red"); 00278 additional.push_back("blue"); 00279 additional.push_back("green"); 00280 00281 event = EventFactory::success(additional); 00282 success = SuccessEvent(additional); 00283 00284 EXPECT_TRUE(EventFactory::isSuccess(event)); 00285 EXPECT_EQ(event.getName(), success.getName()); 00286 EXPECT_EQ(EventFactory::getSuccessName(), event.getName()); 00287 EXPECT_EQ(additional.size(), event.getAdditional().size()); 00288 EXPECT_EQ(event.getAdditional().size(), success.getAdditional().size()); 00289 00290 // Make sure all the objects are equal 00291 for (unsigned c = 0; c < additional.size(); c++) 00292 EXPECT_EQ(additional.at(c), event.getAdditional().at(c)); 00293 00294 // Make sure all the objects are equal between success and created 00295 for (unsigned c = 0; c < event.getAdditional().size(); c++) 00296 EXPECT_EQ(event.getAdditional().at(c), success.getAdditional().at(c)); 00297 } |