Changeset 035a35c in mainline


Ignore:
Timestamp:
2018-07-05T21:41:18Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4e6fb2f
Parents:
d49bae9
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-11-02 21:00:21)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:18)
Message:

cpp: added tests for std::string::compare

Location:
uspace/lib/cpp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/internal/test/tests.hpp

    rd49bae9 r035a35c  
    7474            void test_find();
    7575            void test_substr();
     76            void test_compare();
    7677    };
    7778}
  • uspace/lib/cpp/src/internal/test/string.cpp

    rd49bae9 r035a35c  
    4646        test_find();
    4747        test_substr();
     48        test_compare();
    4849
    4950        return end();
     
    665666        );
    666667    }
     668
     669    void string_test::test_compare()
     670    {
     671        std::string str1{"aabbb"};
     672        std::string str2{"bbbaa"};
     673        std::string str3{"bbb"};
     674
     675        auto res = str1.compare(str1);
     676        test_eq(
     677            "compare equal",
     678            res, 0
     679        );
     680
     681        res = str1.compare(str2.c_str());
     682        test_eq(
     683            "compare less",
     684            res, -1
     685        );
     686
     687        res = str2.compare(str1);
     688        test_eq(
     689            "compare greater",
     690            res, 1
     691        );
     692
     693        res = str1.compare(2, 3, str2);
     694        test_eq(
     695            "compare substring less",
     696            res, -1
     697        );
     698
     699        res = str1.compare(2, 3, str3);
     700        test_eq(
     701            "compare substring equal",
     702            res, 0
     703        );
     704    }
    667705}
Note: See TracChangeset for help on using the changeset viewer.