Leaked source code of windows server 2003
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.

242 lines
7.7 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. #include <media.h>
  8. extern "C" {
  9. DWORD SourceInstallType;
  10. CHAR *SourcePaths[] = { 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. if( iter != m_testCases.end() && (*iter)->mediamatched()) {
  54. os << "Media Matched:";
  55. }
  56. os << "Executing test cases for {" << name() << "}"
  57. << endl << endl;
  58. while (iter != m_testCases.end()) {
  59. if( bVerbose) {
  60. os << dec << setw(3) << setfill('0')
  61. << (iter - m_testCases.begin() + 1) << ": TestCase : ["
  62. << (*iter)->line() << "]" << " " << endl;
  63. }
  64. (*iter)->execute(os);
  65. if (!(*iter)->passed()) {
  66. if( !bVerbose) {
  67. os << dec << setw(3) << setfill('0')
  68. << (iter - m_testCases.begin() + 1) << ": TestCase : ["
  69. << (*iter)->line() << "]" << " FAILED" << endl;
  70. }
  71. (*iter)->dump(os);
  72. allpassed = false;
  73. }
  74. iter++;
  75. }
  76. if (allpassed)
  77. os << "all the test cases passed for this section" << endl;
  78. }
  79. //
  80. // ComplianceTestCase methods
  81. //
  82. void ComplianceTestCase::parse() {
  83. vector<string> tokens;
  84. Tokenize(line(), string("#=,"), tokens);
  85. if (tokens.size() == 7) {
  86. m_expectedResult = ((tokens[6][0] == 'y') || (tokens[6][0] == 'Y'));
  87. sourceDetails();
  88. installationDetails(tokens);
  89. } else {
  90. throw InvalidFormat(line(), section().name());
  91. }
  92. }
  93. void ComplianceTestCase::sourceDetails() {
  94. vector<string> tokens;
  95. char *pstr;
  96. Tokenize(section().name(), string("[#]"), tokens);
  97. if ((tokens.size() == 7) && (tokens[0] == "test")) {
  98. m_sourceSKU = section().file().sourcesSection().value(tokens[1] + "#" + tokens[6]);
  99. m_sourceVAR = section().file().varsSection().value(tokens[5]);
  100. m_sourceVer = atol(tokens[2].c_str()) * 100; // (major * 100 + minor)
  101. pstr = strchr( tokens[2].c_str(), '.');
  102. if( pstr != NULL && *(pstr+1) != NULL) {
  103. m_sourceVer += atol( pstr+1);
  104. }
  105. m_sourceBuild = atol(tokens[3].c_str());
  106. //wprintf( TEXT("SKU=%d, VAR=%d, Ver=%d, Build=%d\n"), m_sourceSKU, m_sourceVAR, m_sourceVer, m_sourceBuild);
  107. if( m_sourceSKU == SourceSku &&
  108. m_sourceVAR == SourceSkuVariation &&
  109. m_sourceVer == SourceVersion &&
  110. m_sourceBuild == SourceBuildNum) {
  111. m_mediamatched = TRUE;
  112. //printf("Media matched\n");
  113. } else {
  114. m_mediamatched = FALSE;
  115. }
  116. } else {
  117. throw Section::InvalidSectionName(section().name());
  118. }
  119. }
  120. void ComplianceTestCase::installationDetails(const vector<string>& tokens) {
  121. int length,i;
  122. int version;
  123. if ((tokens.size() == 7)) {
  124. m_errExpected = section().file().errorsSection().value(tokens[5]);
  125. m_cd.InstallType = section().file().typesSection().value(tokens[0]);
  126. m_cd.InstallVariation = section().file().varsSection().value(tokens[4]);
  127. m_cd.InstallSuite = section().file().suitesSection().value(tokens[3]);
  128. m_cd.RequiresValidation = (section().name().find("#ccp") != section().name().npos);
  129. //m_cd.MinimumVersion = ::strtod(tokens[1].c_str()) * 100;
  130. length = tokens[1].size();
  131. i = 0;
  132. version = 0;
  133. while (i < length) {
  134. if ( tokens[1][i] != '.') {
  135. version = version*10 + tokens[1][i] - '0';
  136. } else {
  137. if (i == (length-3)) { // two decimal places
  138. version = version*100+ (tokens[1][i+1] - '0')*10 + (tokens[1][i+2]-'0');
  139. } else {
  140. version = version*100+ (tokens[1][i+1] - '0');
  141. }
  142. i = length;
  143. }
  144. i++;
  145. }
  146. m_cd.MinimumVersion = version;
  147. // cerr << "minimum version" << m_cd.MinimumVersion << endl;
  148. m_cd.MaximumKnownVersionNt = 510;
  149. if ( m_cd.InstallType & COMPLIANCE_INSTALLTYPE_WIN9X) {
  150. m_cd.BuildNumberWin9x = toUnsignedLong(tokens[2].c_str());
  151. m_cd.BuildNumberNt = 0;
  152. } else {
  153. m_cd.BuildNumberNt = toUnsignedLong(tokens[2].c_str());
  154. m_cd.BuildNumberWin9x = 0;
  155. }
  156. } else
  157. throw Section::InvalidSectionName(section().name());
  158. }
  159. bool ComplianceTestCase::passed() {
  160. bool result = false;
  161. if (m_errExpected) {
  162. // negative testcase
  163. if (m_cd.RequiresValidation) {
  164. // should have failed with expected error code & upgrade flag
  165. result = (!m_passed && (m_errExpected == m_reason) &&
  166. (m_allowUpgrade == m_expectedResult));
  167. } else {
  168. // should pass with expected error code & upgrade flag
  169. // target errors are special case
  170. result = ((m_reason != 0x5) ? m_passed : !m_passed) && (m_errExpected == m_reason) &&
  171. (m_allowUpgrade == m_expectedResult);
  172. }
  173. } else {
  174. result = (m_passed && (m_allowUpgrade == m_expectedResult) && (m_errExpected == m_reason));
  175. }
  176. return result;
  177. }
  178. void ComplianceTestCase::execute(ostream &os) {
  179. m_reason = 0;
  180. m_noUpgrade = true;
  181. if( bUITest) {
  182. m_passed = UITest( m_sourceSKU, m_sourceVAR, m_sourceVer,
  183. m_sourceBuild, &m_cd, &m_reason, &m_noUpgrade) ? true : false;
  184. }else {
  185. m_passed = CheckCompliance(m_sourceSKU, m_sourceVAR, m_sourceVer,
  186. m_sourceBuild, &m_cd, &m_reason, &m_noUpgrade) ? true : false;
  187. }
  188. m_allowUpgrade = (m_noUpgrade) ? false : true;
  189. }
  190. void ComplianceTestCase::dump(ostream &os) {
  191. // (Error expected or not, The error that was expected in hex, Upgrade allowed)
  192. os << "Expected result : (error=" << hex << m_errExpected << ",upgradeallowed="
  193. << ((m_expectedResult) ? "true" : "false") << ")" << endl;
  194. // (Compliant or not(can we do clean install?), Reason in hex, Upgrade allowed)
  195. os << "Actual result : (compliant=" << (m_passed ? "true" : "false")
  196. << ",error=" << hex << m_reason << ",upgradeallowed="
  197. << ((m_allowUpgrade) ? "true" : "false") << ")" << endl;
  198. }