module-tests.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Maxim Likhachev
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  * 
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the University of Pennsylvania nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  * 
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <iostream>
00031 #include <string>
00032 #include <fstream>
00033 #include <gtest/gtest.h>
00034 
00035 using namespace std;
00036 
00037 #include "../headers.h"
00038 
00039 static const std::string PATH_PREFIX("src/test/");
00040 
00041 void diffTest(const std::string& outputStr){
00042   std::string validOutputStr(outputStr + ".valid");
00043   std::ifstream validFile(validOutputStr.c_str());
00044   // If there is no valid file then generate one.
00045   if(!validFile.good()){
00046     std::ifstream newOutputFile(outputStr.c_str());
00047     std::stringbuf sbuf;
00048     newOutputFile >> &sbuf;
00049     std::ofstream newValidFile(validOutputStr.c_str());
00050     newValidFile << sbuf.str();
00051   }
00052   else { // Verify output against the valid file.
00053     std::stringbuf newStrBuf, validStrBuf;
00054     std::ifstream fNew(outputStr.c_str()), fValid(validOutputStr.c_str());
00055     fNew >> &newStrBuf;
00056     fValid >> &validStrBuf;
00057     ASSERT_EQ(newStrBuf.str() == validStrBuf.str(), true);
00058   }
00059 }
00060 
00061 void runARAPlannerTest(const std::string& problem){
00062   try
00063     {
00064       double allocated_time_secs = 0.5; // in seconds
00065       MDPConfig MDPCfg;
00066       EnvironmentNAV2D environment_nav2D;
00067       std::string problemStr = PATH_PREFIX + problem;
00068       ASSERT_EQ(environment_nav2D.InitializeEnv(problemStr.c_str()), true);
00069       ASSERT_EQ(environment_nav2D.InitializeMDPCfg(&MDPCfg), true);
00070 
00071       // plan a path
00072       vector<int> solution_stateIDs_V;
00073       ARAPlanner ara_planner(&environment_nav2D, false);
00074       ASSERT_EQ(ara_planner.set_start(MDPCfg.startstateid), true);
00075       ASSERT_EQ(ara_planner.set_goal(MDPCfg.goalstateid), true);
00076       ASSERT_EQ(ara_planner.replan(allocated_time_secs, &solution_stateIDs_V), true);
00077 
00078       // output the path
00079       std::string outputStr = problemStr + ".out";
00080       FILE* fSol = SBPL_FOPEN(outputStr.c_str(), "w");
00081       for(unsigned int i = 0; i < solution_stateIDs_V.size(); i++) {
00082         environment_nav2D.PrintState(solution_stateIDs_V[i], true, fSol);
00083       }
00084 
00085       SBPL_FCLOSE(fSol);
00086 
00087       // Now apply the file diff test
00088       diffTest(outputStr);
00089     }
00090   catch(...)
00091     {
00092       FAIL() << "Uncaught exception : " << "This is OK on OS X";
00093     }
00094 }
00095 
00096 TEST(araplanner, env1)
00097 {
00098   runARAPlannerTest("env1.cfg");
00099 }
00100 
00101 
00102 int main(int argc, char *argv[])
00103 {
00104   testing::InitGoogleTest(&argc, argv);
00105   return RUN_ALL_TESTS();
00106 }
00107 
00108 
00109 
00110 
00111 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


sbpl
Author(s): Maxim Likhachev/maximl@seas.upenn.edu
autogenerated on Fri Jan 18 2013 13:41:53