/* * This file is a part of PikoTools * and is distributed under the (new) BSD licence. * Author: Tomasz Sowa */ /* * Copyright (c) 2021, Tomasz Sowa * 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. * * * Neither the name Tomasz Sowa nor the names of contributors to this * project may be used to endorse or promote products derived * from this software without specific prior written permission. * * 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 OWNER 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 #include "mainargsparser.h" #include "test.h" #include "mainspaceparser/mainspaceparser.h" #include "utf8/utf8.h" namespace pt { // remove me in the future (when PT will be changed to pt) using namespace PT; namespace pt_mainargsparser_tests { void test_text1() { reset_test_counter("mainargsparser"); MainSpaceParser parser; Space space; const char * argv[] = { "program_name", "-a", "-", "-b", "-c", "-d", "param for d", "-b", "--long", "--foo", "foo-one", "foo-two", "--long-param", "--bar", "bar1", "bar2", "bar3", "-x", "--piggy2=swinka2", "--swinka3", "--bar", "xbar1", "xbar2", "xbar3", }; MainSpaceParser::Status status; Space params; params.add(L"d", 1); params.add(L"foo", 2); params.add(L"bar", 3); params.add(L"piggy", 1); params.add(L"piggy2", 1); size_t len = sizeof(argv) / sizeof(const char *); status = parser.parse(len, argv, space, params); if( status != MainSpaceParser::status_ok ) { std::wstring & err = parser.get_wrong_option(); std::string err_str; WideToUTF8(err, err_str); std::cout << "blad: " << (int)status << ": " << err_str << std::endl; } test(status, MainSpaceParser::status_ok); std::cout << space.serialize_to_json_str() << std::endl; } void make_tests() { test_text1(); // test_text2(); // test_text3(); // test_text4(); // test_text5(); } } }