Skip to content

Commit

Permalink
unit test for stuff (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerKuemmerle committed Sep 17, 2018
1 parent ecff08c commit 553a86c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion g2o/stuff/string_tools.cpp
Expand Up @@ -73,7 +73,7 @@ std::string trimRight(const std::string& s)
return s;
string::size_type b = 0;
string::size_type e = s.find_last_not_of(" \t\n");
if(b == string::npos)
if(e == string::npos)
return "";
return std::string(s, b, e - b + 1);
}
Expand Down
1 change: 1 addition & 0 deletions unit_test/CMakeLists.txt
Expand Up @@ -36,6 +36,7 @@ macro(create_test target)
add_test (NAME ${target} COMMAND $<TARGET_FILE:${target}>)
endmacro(create_test)

ADD_SUBDIRECTORY(stuff)
ADD_SUBDIRECTORY(slam2d)
ADD_SUBDIRECTORY(slam3d)
ADD_SUBDIRECTORY(general)
5 changes: 5 additions & 0 deletions unit_test/stuff/CMakeLists.txt
@@ -0,0 +1,5 @@
add_executable(unittest_stuff
string_tools_tests.cpp
)
target_link_libraries(unittest_stuff stuff)
create_test(unittest_stuff)
48 changes: 48 additions & 0 deletions unit_test/stuff/string_tools_tests.cpp
@@ -0,0 +1,48 @@
// g2o - General Graph Optimization
// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "gtest/gtest.h"

#include "g2o/stuff/string_tools.h"

TEST(Stuff, Trim)
{
ASSERT_EQ("abc", g2o::trim("abc "));
ASSERT_EQ("abc", g2o::trim(" abc"));
ASSERT_EQ("abc", g2o::trim(" abc "));
ASSERT_EQ("abc", g2o::trim("abc"));
ASSERT_EQ("", g2o::trim(" "));
ASSERT_EQ("abc ", g2o::trimLeft("abc "));
ASSERT_EQ("abc", g2o::trimLeft(" abc"));
ASSERT_EQ("abc ", g2o::trimLeft(" abc "));
ASSERT_EQ("abc", g2o::trimLeft("abc"));
ASSERT_EQ("", g2o::trimLeft(" "));
ASSERT_EQ("abc", g2o::trimRight("abc "));
ASSERT_EQ(" abc", g2o::trimRight(" abc"));
ASSERT_EQ(" abc", g2o::trimRight(" abc "));
ASSERT_EQ("abc", g2o::trimRight("abc"));
ASSERT_EQ("", g2o::trimRight(" "));
}

0 comments on commit 553a86c

Please sign in to comment.