|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Example CTestStep derived implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 @file WriteStringStep.cpp |
|
23 */ |
|
24 #include "ReadWriteConfigNegStep.h" |
|
25 #include "Te_RegStepTestSuiteDefs.h" |
|
26 |
|
27 #define StringDefine(s) _LIT(K##s, #s) |
|
28 StringDefine(IntValue); |
|
29 StringDefine(BoolValue); |
|
30 StringDefine(HexValue); |
|
31 StringDefine(StringValue); |
|
32 |
|
33 CReadWriteConfigNegStep::~CReadWriteConfigNegStep() |
|
34 /** |
|
35 * Destructor |
|
36 */ |
|
37 { |
|
38 } |
|
39 |
|
40 CReadWriteConfigNegStep::CReadWriteConfigNegStep() |
|
41 /** |
|
42 * Constructor |
|
43 */ |
|
44 { |
|
45 SetTestStepName(KReadWriteConfigNegStep); |
|
46 } |
|
47 |
|
48 TVerdict CReadWriteConfigNegStep::doTestStepPreambleL() |
|
49 /** |
|
50 * @return - TVerdict code |
|
51 * Override of base class virtual |
|
52 */ |
|
53 { |
|
54 // There is no initiation work so set this result to pass. |
|
55 SetTestStepResult(EPass); |
|
56 return TestStepResult(); |
|
57 } |
|
58 |
|
59 |
|
60 TVerdict CReadWriteConfigNegStep::doTestStepL() |
|
61 /** |
|
62 * @return - TVerdict code |
|
63 * Override of base class pure virtual |
|
64 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
65 * not leave. That being the case, the current test result value will be EPass. |
|
66 */ |
|
67 { |
|
68 INFO_PRINTF1(_L("Negative test of read/write config file.")); |
|
69 SetTestStepResult(EFail); |
|
70 |
|
71 TBool ret = EFalse; |
|
72 ret = TestInt(); |
|
73 ret &= TestBool(); |
|
74 ret &= TestHex(); |
|
75 ret &= TestString(); |
|
76 |
|
77 if (ret) |
|
78 { |
|
79 SetTestStepResult(EPass); |
|
80 } |
|
81 return TestStepResult(); |
|
82 } |
|
83 |
|
84 TVerdict CReadWriteConfigNegStep::doTestStepPostambleL() |
|
85 /** |
|
86 * @return - TVerdict code |
|
87 * Override of base class virtual |
|
88 */ |
|
89 { |
|
90 return TestStepResult(); |
|
91 } |
|
92 |
|
93 TBool CReadWriteConfigNegStep::TestInt() |
|
94 { |
|
95 INFO_PRINTF1(_L("---Start negative test of read/write integer from/to configuration file...")); |
|
96 |
|
97 TInt value = 10; |
|
98 TInt getValue = 0; |
|
99 TBool ret = EFalse; |
|
100 |
|
101 if (!GetIntFromConfig(ConfigSection(), KIntValue, getValue)) |
|
102 { |
|
103 if (0 == ConfigSection().Length()) |
|
104 { |
|
105 ret = !WriteIntToConfig(ConfigSection(), KIntValue, value); |
|
106 } |
|
107 else |
|
108 { |
|
109 ret = WriteIntToConfig(ConfigSection(), KIntValue, value); |
|
110 } |
|
111 } |
|
112 |
|
113 INFO_PRINTF1(ret?_L("Test Passed!"):_L("Test Failed!")); |
|
114 return ret; |
|
115 } |
|
116 |
|
117 TBool CReadWriteConfigNegStep::TestBool() |
|
118 { |
|
119 INFO_PRINTF1(_L("---Start negative test of read/write bool from/to configuration file...")); |
|
120 |
|
121 TBool value = EFalse; |
|
122 TBool getValue = EFalse; |
|
123 TBool ret = EFalse; |
|
124 |
|
125 if (!GetBoolFromConfig(ConfigSection(), KBoolValue, getValue) |
|
126 && !WriteBoolToConfig(ConfigSection(), KBoolValue, 10)) |
|
127 { |
|
128 if (0 == ConfigSection().Length()) |
|
129 { |
|
130 ret = !WriteBoolToConfig(ConfigSection(), KBoolValue, value); |
|
131 } |
|
132 else |
|
133 { |
|
134 ret = WriteBoolToConfig(ConfigSection(), KBoolValue, value); |
|
135 } |
|
136 } |
|
137 |
|
138 INFO_PRINTF1(ret?_L("Test Passed!"):_L("Test Failed!"));; |
|
139 return ret; |
|
140 } |
|
141 |
|
142 TBool CReadWriteConfigNegStep::TestHex() |
|
143 { |
|
144 INFO_PRINTF1(_L("---Start negative test of read/write hex from/to configuration file...")); |
|
145 |
|
146 TInt value = 0x00AB; |
|
147 TInt getValue = 0; |
|
148 TBool ret = EFalse; |
|
149 if (!GetHexFromConfig(ConfigSection(), KHexValue, getValue)) |
|
150 { |
|
151 ret = (0==ConfigSection().Length()?!WriteHexToConfig(ConfigSection(), KHexValue, value):WriteHexToConfig(ConfigSection(), KHexValue, value)); |
|
152 } |
|
153 |
|
154 INFO_PRINTF1(ret?_L("Test Passed!"):_L("Test Failed!"));; |
|
155 return ret; |
|
156 } |
|
157 |
|
158 TBool CReadWriteConfigNegStep::TestString() |
|
159 { |
|
160 INFO_PRINTF1(_L("---Start negative test of read/write string from/to configuration file...")); |
|
161 TBool ret = EFalse; |
|
162 |
|
163 _LIT(KChangedString, "Changed string!"); |
|
164 TPtrC getValue; |
|
165 |
|
166 if (!GetStringFromConfig(ConfigSection(), KStringValue, getValue)) |
|
167 { |
|
168 ret = (0==ConfigSection().Length()?!WriteStringToConfig(ConfigSection(), KStringValue, KChangedString()):WriteStringToConfig(ConfigSection(), KStringValue, KChangedString())); |
|
169 } |
|
170 |
|
171 INFO_PRINTF1(ret?_L("Test Passed!"):_L("Test Failed!"));; |
|
172 return ret; |
|
173 } |