Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
5.8 KiB

  1. #pragma warning( disable:4786 )
  2. #include <section.h>
  3. #include <cstdlib>
  4. #include <strutil.h>
  5. #include <compfile.h>
  6. #include <iomanip>
  7. extern "C" {
  8. DWORD SourceInstallType = 0;
  9. CHAR *SourcePaths[] = { 0 };
  10. CHAR *NativeSourcePaths[] = {0};
  11. DWORD OsVersion;
  12. VOID GetSourceInstallType(LPDWORD InstallVariation){}
  13. };
  14. //
  15. // ValueSection methods
  16. //
  17. void ValueSection::parse() {
  18. vector<string>::const_iterator iter = lines().begin();
  19. while (iter != lines().end()) {
  20. vector<string> tokens;
  21. Tokenize((const string&)(*iter), string(" ="), tokens);
  22. if (tokens.size() != 2)
  23. throw InvalidSectionFormat(name());
  24. m_values[tokens[0]] = toUnsignedLong(tokens[1].c_str());
  25. iter++;
  26. }
  27. }
  28. //
  29. // TestSection methods
  30. //
  31. void TestSection::parse() {
  32. vector<string>::const_iterator iter = lines().begin();
  33. while (iter != lines().end()) {
  34. m_testCases.push_back(testCaseFactory().create(*this, *iter));
  35. iter++;
  36. }
  37. }
  38. TestSection& TestSection::operator=(const TestSection& rhs){
  39. cerr << "Copying section " << endl;
  40. *(Section *)this = (Section&)rhs;
  41. m_testCases.clear();
  42. vector<TestCase*>::const_iterator iter = rhs.m_testCases.begin();
  43. while (iter != rhs.m_testCases.end()) {
  44. m_testCases.push_back(testCaseFactory().create(**iter));
  45. iter++;
  46. }
  47. return *this;
  48. }
  49. void TestSection::executeTestCases(ostream& os) {
  50. vector<TestCase*>::iterator iter = m_testCases.begin();
  51. bool allpassed = true;
  52. os << endl << endl
  53. << "Executing test cases for {" << name() << "}"
  54. << endl << endl;
  55. while (iter != m_testCases.end()) {
  56. (*iter)->execute(os);
  57. if (!(*iter)->passed()) {
  58. os << dec << setw(3) << setfill('0')
  59. << (iter - m_testCases.begin() + 1) << ": TestCase : ["
  60. << (*iter)->line() << "]" << " FAILED" << endl;
  61. (*iter)->dump(os);
  62. allpassed = false;
  63. }
  64. iter++;
  65. }
  66. if (allpassed)
  67. os << "all the test cases passed for this section" << endl;
  68. }
  69. //
  70. // ComplianceTestCase methods
  71. //
  72. void ComplianceTestCase::parse() {
  73. vector<string> tokens;
  74. Tokenize(line(), string("#=,"), tokens);
  75. if (tokens.size() == 7) {
  76. m_expectedResult = ((tokens[6][0] == 'y') || (tokens[6][0] == 'Y'));
  77. sourceDetails();
  78. installationDetails(tokens);
  79. } else {
  80. throw InvalidFormat(line(), section().name());
  81. }
  82. }
  83. void ComplianceTestCase::sourceDetails() {
  84. vector<string> tokens;
  85. Tokenize(section().name(), string("[#]"), tokens);
  86. if ((tokens.size() == 7) && (tokens[0] == "test")) {
  87. m_sourceSKU = section().file().sourcesSection().value(tokens[1] + "#" + tokens[6]);
  88. m_sourceVAR = section().file().varsSection().value(tokens[5]);
  89. m_sourceVer = atof(tokens[2].c_str()) * 100; // (major * 100 + minor)
  90. m_sourceBuild = atol(tokens[3].c_str());
  91. }
  92. else
  93. throw Section::InvalidSectionName(section().name());
  94. }
  95. void ComplianceTestCase::installationDetails(const vector<string>& tokens) {
  96. int length,i;
  97. int version;
  98. if ((tokens.size() == 7)) {
  99. m_errExpected = section().file().errorsSection().value(tokens[5]);
  100. m_cd.InstallType = section().file().typesSection().value(tokens[0]);
  101. m_cd.InstallVariation = section().file().varsSection().value(tokens[4]);
  102. m_cd.InstallSuite = section().file().suitesSection().value(tokens[3]);
  103. m_cd.RequiresValidation = (section().name().find("#ccp") != section().name().npos);
  104. //m_cd.MinimumVersion = ::strtod(tokens[1].c_str()) * 100;
  105. length = tokens[1].size();
  106. i = 0;
  107. version = 0;
  108. while (i < length) {
  109. if( tokens[1][i] != '.'){
  110. version = version*10 + tokens[1][i] - '0';
  111. }
  112. else
  113. {
  114. if (i == (length-3)) { // two decimal places
  115. version = version*100+ (tokens[1][i+1] - '0')*10 + (tokens[1][i+2]-'0');
  116. }
  117. else{
  118. version = version*100+ (tokens[1][i+1] - '0');
  119. }
  120. i = length;
  121. }
  122. i++;
  123. }
  124. m_cd.MinimumVersion = version;
  125. // cerr << "minimum version" << m_cd.MinimumVersion << endl;
  126. m_cd.MaximumKnownVersionNt = 510;
  127. if( m_cd.InstallType & COMPLIANCE_INSTALLTYPE_WIN9X) {
  128. m_cd.BuildNumberWin9x = toUnsignedLong(tokens[2].c_str());
  129. m_cd.BuildNumberNt = 0;
  130. } else {
  131. m_cd.BuildNumberNt = toUnsignedLong(tokens[2].c_str());
  132. m_cd.BuildNumberWin9x = 0;
  133. }
  134. }
  135. else
  136. throw Section::InvalidSectionName(section().name());
  137. }
  138. bool ComplianceTestCase::passed() {
  139. bool result = false;
  140. if (m_errExpected) {
  141. // negative testcase
  142. if (m_cd.RequiresValidation) {
  143. // should have failed with expected error code & upgrade flag
  144. result = (!m_passed && (m_errExpected == m_reason) &&
  145. (m_allowUpgrade == m_expectedResult));
  146. } else {
  147. // should pass with expected error code & upgrade flag
  148. // target errors are special case
  149. result = ((m_reason != 0x5) ? m_passed : !m_passed) && (m_errExpected == m_reason) &&
  150. (m_allowUpgrade == m_expectedResult);
  151. }
  152. }
  153. else {
  154. result = (m_passed && (m_allowUpgrade == m_expectedResult));
  155. }
  156. return result;
  157. }
  158. void ComplianceTestCase::execute(ostream &os) {
  159. m_reason = 0;
  160. m_noUpgrade = true;
  161. m_passed = CheckCompliance(m_sourceSKU, m_sourceVAR, m_sourceVer,
  162. m_sourceBuild, &m_cd, &m_reason, &m_noUpgrade) ? true : false;
  163. m_allowUpgrade = (m_noUpgrade) ? false : true;
  164. }
  165. void ComplianceTestCase::dump(ostream &os) {
  166. // (Error expected or not, The error that was expected in hex, Upgrade allowed)
  167. os << "Expected result : (error=" << hex << m_errExpected << ",upgradeallowed="
  168. << ((m_expectedResult) ? "true" : "false") << ")" << endl;
  169. // (Compliant or not(can we do clean install?), Reason in hex, Upgrade allowed)
  170. os << "Actual result : (compliant=" << (m_passed ? "true" : "false")
  171. << ",error=" << hex << m_reason << ",upgradeallowed="
  172. << ((m_allowUpgrade) ? "true" : "false") << ")" << endl;
  173. }