"Fossies" - the Fresh Open Source Software Archive

Member "cppcheck-1.89/test/testtokenlist.cpp" (1 Sep 2019, 2412 Bytes) of package /windows/misc/cppcheck-1.89.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "testtokenlist.cpp": 1.86_vs_1.87.

    1 /*
    2  * Cppcheck - A tool for static C/C++ code analysis
    3  * Copyright (C) 2007-2019 Cppcheck team.
    4  *
    5  * This program is free software: you can redistribute it and/or modify
    6  * it under the terms of the GNU General Public License as published by
    7  * the Free Software Foundation, either version 3 of the License, or
    8  * (at your option) any later version.
    9  *
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   17  */
   18 
   19 #include "settings.h"
   20 #include "testsuite.h"
   21 #include "token.h"
   22 #include "tokenlist.h"
   23 
   24 #include <sstream>
   25 #include <string>
   26 
   27 class TestTokenList : public TestFixture {
   28 public:
   29     TestTokenList() : TestFixture("TestTokenList") {
   30     }
   31 
   32 private:
   33     Settings settings;
   34 
   35     void run() OVERRIDE {
   36         TEST_CASE(testaddtoken1);
   37         TEST_CASE(testaddtoken2);
   38         TEST_CASE(inc);
   39     }
   40 
   41     // inspired by #5895
   42     void testaddtoken1() {
   43         const std::string code = "0x89504e470d0a1a0a";
   44         TokenList tokenlist(&settings);
   45         tokenlist.addtoken(code, 1, 1, false);
   46         ASSERT_EQUALS("9894494448401390090U", tokenlist.front()->str());
   47         // that is supposed to break on 32bit
   48         //unsigned long numberUL(0);
   49         //std::istringstream(tokenlist.front()->str()) >> numberUL;
   50         //ASSERT_EQUALS(9894494448401390090U, numberUL);
   51         unsigned long long numberULL(0);
   52         std::istringstream(tokenlist.front()->str()) >> numberULL;
   53         ASSERT_EQUALS(9894494448401390090U, numberULL);
   54     }
   55 
   56     void testaddtoken2() {
   57         const std::string code = "0xF0000000";
   58         settings.int_bit = 32;
   59         TokenList tokenlist(&settings);
   60         tokenlist.addtoken(code, 1, 1, false);
   61         ASSERT_EQUALS("4026531840U", tokenlist.front()->str());
   62     }
   63 
   64     void inc() const {
   65         const char code[] = "a++1;1++b;";
   66 
   67         errout.str("");
   68 
   69         // tokenize..
   70         TokenList tokenlist(&settings);
   71         std::istringstream istr(code);
   72         tokenlist.createTokens(istr, "a.cpp");
   73 
   74         ASSERT(Token::simpleMatch(tokenlist.front(), "a + + 1 ; 1 + + b ;"));
   75     }
   76 };
   77 
   78 REGISTER_TEST(TestTokenList)