rambrain
testConfigLine.cpp
Go to the documentation of this file.
1 /* rambrain - a dynamical physical memory extender
2  * Copyright (C) 2015 M. Imgrund, A. Arth
3  * mimgrund (at) mpifr-bonn.mpg.de
4  * arth (at) usm.uni-muenchen.de
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <gtest/gtest.h>
21 #include "configreader.h"
22 
23 using namespace std;
24 using namespace rambrain;
25 
29 TEST ( configLine, Unit_SetValue )
30 {
31  configLine<global_bytesize> cl1 ( "cl1", 0uLL, regexMatcher::integer );
32  EXPECT_EQ ( 0uLL, cl1.value );
33  cl1.setValue ( "123" );
34  EXPECT_EQ ( 123uLL, cl1.value );
35 
36  configLine<global_bytesize> cl2 ( "cl2", 0uLL, regexMatcher::integer | regexMatcher::units );
37  cl2.setValue ( "123 kb" );
38  EXPECT_EQ ( 123 * kib, cl2.value );
39 
40  cl2.setValue ( "456 MB" );
41  EXPECT_EQ ( 456 * mib, cl2.value );
42 
43  cl2.setValue ( "789 Gb" );
44  EXPECT_EQ ( 789 * gig, cl2.value );
45 }
46 
50 TEST ( configLine, Unit_SetValueMissingUnit )
51 {
52  configLine<global_bytesize> cl ( "cl", 0uLL, regexMatcher::integer | regexMatcher::units );
53  EXPECT_EQ ( 0uLL, cl.value );
54  cl.setValue ( "123" );
55  EXPECT_EQ ( 123uLL, cl.value );
56 }
57 
virtual void setValue(const string &str)
Reset the value from a string.
Definition: configreader.h:106
Class for config key value pairs represented by a line in a config file.
Definition: configreader.h:87
const global_bytesize gig
Definition: common.h:69
const global_bytesize kib
Definition: common.h:67
STL namespace.
TEST(configLine, Unit_SetValue)
const global_bytesize mib
Definition: common.h:68