inifile.test.cc revision 13465
17199Sgblack@eecs.umich.edu/* 27199Sgblack@eecs.umich.edu * Copyright (c) 2018 ARM Limited 37199Sgblack@eecs.umich.edu * All rights reserved 47199Sgblack@eecs.umich.edu * 57199Sgblack@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 67199Sgblack@eecs.umich.edu * All rights reserved. 77199Sgblack@eecs.umich.edu * 87199Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 97199Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 107199Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 117199Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 127199Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 137199Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 147199Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 157199Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 167199Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 177199Sgblack@eecs.umich.edu * this software without specific prior written permission. 187199Sgblack@eecs.umich.edu * 197199Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 207199Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 217199Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 227199Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 237199Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 247199Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 257199Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 267199Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 277199Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 287199Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 297199Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 307199Sgblack@eecs.umich.edu * 317199Sgblack@eecs.umich.edu * Authors: Nathan Binkert 327199Sgblack@eecs.umich.edu * Steve Reinhardt 337199Sgblack@eecs.umich.edu */ 347199Sgblack@eecs.umich.edu 357199Sgblack@eecs.umich.edu#include <gtest/gtest.h> 367199Sgblack@eecs.umich.edu 377199Sgblack@eecs.umich.edu#include <fstream> 387199Sgblack@eecs.umich.edu#include <iostream> 397199Sgblack@eecs.umich.edu#include <string> 407199Sgblack@eecs.umich.edu#include <vector> 417199Sgblack@eecs.umich.edu 427199Sgblack@eecs.umich.edu#include "base/inifile.hh" 437199Sgblack@eecs.umich.edu 447199Sgblack@eecs.umich.eduusing namespace std; 457199Sgblack@eecs.umich.edu 467199Sgblack@eecs.umich.edunamespace { 477199Sgblack@eecs.umich.edu 487199Sgblack@eecs.umich.edustd::istringstream iniFile(R"ini_file( 497199Sgblack@eecs.umich.edu[General] 507199Sgblack@eecs.umich.edu Test1=BARasdf 517199Sgblack@eecs.umich.edu Test2=bar 527199Sgblack@eecs.umich.edu 537199Sgblack@eecs.umich.edu[Junk] 547199Sgblack@eecs.umich.eduTest3=yo 557199Sgblack@eecs.umich.eduTest4=mama 567199Sgblack@eecs.umich.edu 577199Sgblack@eecs.umich.edu[Foo] 587202Sgblack@eecs.umich.eduFoo1=89 597202Sgblack@eecs.umich.eduFoo2=384 607202Sgblack@eecs.umich.edu 617202Sgblack@eecs.umich.edu[General] 627202Sgblack@eecs.umich.eduTest3=89 638301SAli.Saidi@ARM.com 648303SAli.Saidi@ARM.com[Junk] 658303SAli.Saidi@ARM.comTest4+=mia 668303SAli.Saidi@ARM.com)ini_file"); 678303SAli.Saidi@ARM.com 688303SAli.Saidi@ARM.com}; 698303SAli.Saidi@ARM.com 708301SAli.Saidi@ARM.comTEST(Initest, MatchFound) 718301SAli.Saidi@ARM.com{ 727202Sgblack@eecs.umich.edu IniFile simConfigDB; 737202Sgblack@eecs.umich.edu simConfigDB.load(iniFile); 747599Sminkyu.jeong@arm.com 757783SGiacomo.Gabrielli@arm.com std::string value; 767202Sgblack@eecs.umich.edu 777202Sgblack@eecs.umich.edu auto ret = simConfigDB.find("General", "Test2", value); 787202Sgblack@eecs.umich.edu ASSERT_TRUE(ret); 797202Sgblack@eecs.umich.edu ASSERT_STREQ(value.c_str(), "bar"); 807202Sgblack@eecs.umich.edu 817202Sgblack@eecs.umich.edu ret = simConfigDB.find("Junk", "Test3", value); 827202Sgblack@eecs.umich.edu ASSERT_TRUE(ret); 837599Sminkyu.jeong@arm.com ASSERT_STREQ(value.c_str(), "yo"); 847783SGiacomo.Gabrielli@arm.com 857202Sgblack@eecs.umich.edu ret = simConfigDB.find("Junk", "Test4", value); 867202Sgblack@eecs.umich.edu ASSERT_TRUE(ret); 877202Sgblack@eecs.umich.edu ASSERT_STREQ(value.c_str(), "mama mia"); 887202Sgblack@eecs.umich.edu 897202Sgblack@eecs.umich.edu ret = simConfigDB.find("General", "Test1", value); 907400SAli.Saidi@ARM.com ASSERT_TRUE(ret); 918303SAli.Saidi@ARM.com ASSERT_STREQ(value.c_str(), "BARasdf"); 928303SAli.Saidi@ARM.com 938303SAli.Saidi@ARM.com ret = simConfigDB.find("General", "Test3", value); 948303SAli.Saidi@ARM.com ASSERT_TRUE(ret); 958303SAli.Saidi@ARM.com ASSERT_STREQ(value.c_str(), "89"); 968303SAli.Saidi@ARM.com} 978303SAli.Saidi@ARM.com 988303SAli.Saidi@ARM.comTEST(Initest, MatchNotFound) 998303SAli.Saidi@ARM.com{ 1008303SAli.Saidi@ARM.com IniFile simConfigDB; 1018303SAli.Saidi@ARM.com simConfigDB.load(iniFile); 1028303SAli.Saidi@ARM.com 1038303SAli.Saidi@ARM.com std::string value; 1047202Sgblack@eecs.umich.edu 1057202Sgblack@eecs.umich.edu auto ret = simConfigDB.find("Junk2", "test3", value); 1067202Sgblack@eecs.umich.edu ASSERT_FALSE(ret); 1077599Sminkyu.jeong@arm.com 1087599Sminkyu.jeong@arm.com ret = simConfigDB.find("Junk", "test4", value); 1097202Sgblack@eecs.umich.edu ASSERT_FALSE(ret); 1107202Sgblack@eecs.umich.edu} 1117202Sgblack@eecs.umich.edu