int main() { Complex z1(4,3); z1.Show(); std::cout << "z1="<< z1 <<std::endl; Complex z2(4,-3); z2.Show(); std::cout << "z2="<< z2 <<std::endl; Complex z3(0,3); z3.Show(); std::cout << "z3="<< z3 <<std::endl; Complex z4(1,0); z4.Show(); std::cout << "z4="<< z4 <<std::endl; Complex z5(0,5); z5.Show(); std::cout << "z5="<< z5 <<std::endl; Complex z6(0,0); z6.Show(); std::cout << "z6="<< z6 <<std::endl; (z1 + z2).Show(); (z1 - z2).Show(); (z1 * z1).Show(); (z1 * z2).Show(); std::cout << "|z1| = " << z1.GetLenth() << std::endl; z1.Conjugate().Show(); z2.Conjugate().Show(); return 0; }
void CParametricSurface::Vertex(Vec2 domain) { Vec3 p0, p1, p2, p3; Vec3 normal; float u = domain.x; float v = domain.y; Eval(domain, p0); Vec2 z1(u + du/2, v); Eval(z1, p1); Vec2 z2(u + du/2 + du, v); Eval(z2, p3); if (flipped) { Vec2 z3(u + du/2, v - dv); Eval(z3, p2); } else { Vec2 z4(u + du/2, v + dv); Eval(z4, p2); } const float epsilon = 0.00001f; Vec3 tangent = p3 - p1; Vec3 binormal = p2 - p1; MatrixVec3CrossProduct(normal, tangent, binormal); if (normal.length() < epsilon) normal = p0; normal.normalize(); if (tangent.length() < epsilon) MatrixVec3CrossProduct(tangent, binormal, normal); tangent.normalize(); binormal.normalize(); binormal = binormal * -1.0f; /* if (CustomAttributeLocation() != -1) glVertexAttrib1f(CustomAttributeLocation(), CustomAttributeValue(domain)); */ //glNormal(normal); //glTexCoord(domain); //glVertex(p0); int vertexIndex = totalVertex * 14; vertexBuffer[vertexIndex++] = p0.x; vertexBuffer[vertexIndex++] = p0.y; vertexBuffer[vertexIndex++] = p0.z; vertexBuffer[vertexIndex++] = domain.x; vertexBuffer[vertexIndex++] = domain.y; vertexBuffer[vertexIndex++] = normal.x; vertexBuffer[vertexIndex++] = normal.y; vertexBuffer[vertexIndex++] = normal.z; vertexBuffer[vertexIndex++] = tangent.x; vertexBuffer[vertexIndex++] = tangent.y; vertexBuffer[vertexIndex++] = tangent.z; vertexBuffer[vertexIndex++] = binormal.x; vertexBuffer[vertexIndex++] = binormal.y; vertexBuffer[vertexIndex++] = binormal.z; }
void MainWindow::slot1() { qreal *b = a->getParams(ui->comboBox->currentText()); QVariant z1(b[0]); ui->lineEdit_2->setText(z1.toString()); QVariant z2(b[1]); ui->lineEdit_3->setText(z2.toString()); QVariant z3(b[2]); ui->lineEdit_4->setText(z3.toString()); QVariant z4(b[3]); ui->lineEdit_5->setText(z4.toString()); }
// Send out a normal, texture coordinate, vertex coordinate, and an optional custom attribute. void TParametricSurface::Vertex(vec2 domain) { vec3 p0, p1, p2, p3; vec3 normal; float u = domain.u; float v = domain.v; Eval(domain, p0); vec2 z1(u + du/2, v); Eval(z1, p1); vec2 z2(u + du/2 + du, v); Eval(z2, p3); if (flipped) { vec2 z3(u + du/2, v - dv); Eval(z3, p2); } else { vec2 z4(u + du/2, v + dv); Eval(z4, p2); } const float epsilon = 0.00001f; vec3 tangent = p3 - p1; vec3 binormal = p2 - p1; normal = cross(tangent, binormal); if (normal.magnitude() < epsilon) normal = p0; normal.unitize(); if (tangentLoc != -1) { if (tangent.magnitude() < epsilon) tangent = cross(binormal, normal); tangent.unitize(); glVertexAttrib(tangentLoc, tangent); } if (binormalLoc != -1) { binormal.unitize(); glVertexAttrib(binormalLoc, -binormal); } if (CustomAttributeLocation() != -1) glVertexAttrib1f(CustomAttributeLocation(), CustomAttributeValue(domain)); glNormal(normal); glTexCoord(domain); glVertex(p0); }
void ComplexTestSuite::Equality() { gsl::complex z1(1.2, 3.2); gsl::complex z2(1.2, 3.2); gsl::complex z3(3.4, 6.3); gsl::complex z4( z3 ); CPPUNIT_ASSERT ( z1 == z2 ); CPPUNIT_ASSERT ( z1 != z3 ); CPPUNIT_ASSERT ( z4 == z3 ); CPPUNIT_ASSERT ( z3 > z1 ); CPPUNIT_ASSERT ( z3 <= z4 ); CPPUNIT_ASSERT ( z2 <= z3 ); CPPUNIT_ASSERT ( z2 < z4 ); CPPUNIT_ASSERT ( z3 >= z1 ); CPPUNIT_ASSERT ( z3 >= z2 ); }
/** * CoreCamera constructor. Initializes the CoreCamera to the * default mode allowing generic 3D-scene navigation. */ CoreCamera::CoreCamera():BaseCamera(){ requirePresenceOfMouse(objectType(), "CoreCamera"); mode = CAMERA_DEFAULT_MODE; focus_frame = new Frame(); Vector z1(0.0, 1.0, 0.0); Vector z2(1.0, 0.0, 0.0); Vector z3(0.0, 0.0, 1.0); focus_frame->setOrientationAxes(z1, z2, z3); setParentFrame(focus_frame); prev_mouse_x = 0; prev_mouse_y = 0; scale_x = 1.0; scale_y = 1.0; scale_z = 1.0; rotate_camera_button_code = 114; // 'r' zoom_camera_button_code = 122; // 'z' }
void ComplexTestSuite::IO() { gsl::complex z1(1,2); std::string s1("1 + 2"); s1 += IMAG_SYMB; std::stringstream ss1; ss1 << z1; CPPUNIT_ASSERT(s1 == ss1.str()); gsl::complex z2(1,-2); std::string s2("1 - 2"); s2 += IMAG_SYMB; std::stringstream ss2; ss2 << z2; CPPUNIT_ASSERT(s2 == ss2.str()); gsl::complex z3(0,2); std::string s3("2"); s3 += IMAG_SYMB; std::stringstream ss3; ss3 << z3; CPPUNIT_ASSERT(s3 == ss3.str()); gsl::complex z4(0,-3); std::string s4("-3"); s4 += IMAG_SYMB; std::stringstream ss4; ss4 << z4; CPPUNIT_ASSERT(s4 == ss4.str()); gsl::complex z5(1,0); std::string s5("1"); std::stringstream ss5; ss5 << z5; CPPUNIT_ASSERT(s5 == ss5.str()); gsl::complex z6(0,0); std::string s6("0"); std::stringstream ss6; ss6 << z6; CPPUNIT_ASSERT(s6 == ss6.str()); }
void mu11(int x,int y,char po[24],int f) { int m,n; static int i=0; for(m=0;m<4;m++) { for(n=0;n<2;n++) { blackground z3(x,y,m,n,BACKGROUND_BLUE|BACKGROUND_RED|BACKGROUND_INTENSITY|FOREGROUND_INTENSITY); z3.display1(); if(f&&i<24) { po[i++]=x+m; // x po[i++]=y+n; // y po[i++]=4; // 颜色 } } } SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY); printf("\n"); }
void ComplexTestSuite::Construction() { gsl::complex z1; gsl::complex z2( 1.3, 2.1 ); CPPUNIT_ASSERT ( z2.x() == 1.3 ); CPPUNIT_ASSERT ( z2.y() == 2.1 ); z1 = z2; CPPUNIT_ASSERT ( z1.x() == 1.3 ); CPPUNIT_ASSERT ( z1.y() == 2.1 ); gsl::complex z3( 4.5 ); CPPUNIT_ASSERT ( z3.x() == 4.5 ); CPPUNIT_ASSERT ( z3.y() == realZero ); real r = z2; CPPUNIT_ASSERT_DOUBLES_EQUAL ( sqrt(1.3*1.3 + 2.1*2.1), r, 1e-15 ); }
void f(Z& z) { Z z2; // expected-error{{no matching constructor for initialization}} Z z3(z); }
bool TestSecBlock() { std::cout << "\nTesting SecBlock...\n\n"; bool pass1=true, pass2=true, pass3=true, pass4=true, pass5=true, pass6=true, pass7=true, temp=false; //************ Allocators ************// { std::basic_string<char, std::char_traits<char>, AllocatorWithCleanup<char, false> > s1; std::basic_string<char, std::char_traits<char>, AllocatorWithCleanup<char, true> > s2; s1.resize(1024); s2.resize(1024); std::vector<byte, AllocatorWithCleanup<byte, false> > v1; std::vector<byte, AllocatorWithCleanup<byte, true> > v2; v1.resize(1024); v2.resize(1024); } //********** Zeroized block **********// { // NULL ptr with a size means to create a new SecBlock with all elements zero'd SecByteBlock z1(NULLPTR, 256); temp = true; for (size_t i = 0; i < z1.size(); i++) temp &= (z1[i] == 0); pass1 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Zeroized byte array\n"; SecBlock<word32> z2(NULLPTR, 256); temp = true; for (size_t i = 0; i < z2.size(); i++) temp &= (z2[i] == 0); pass1 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Zeroized word32 array\n"; SecBlock<word64> z3(NULLPTR, 256); temp = true; for (size_t i = 0; i < z3.size(); i++) temp &= (z3[i] == 0); pass1 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Zeroized word64 array\n"; #if defined(CRYPTOPP_WORD128_AVAILABLE) SecBlock<word128> z4(NULLPTR, 256); temp = true; for (size_t i = 0; i < z4.size(); i++) temp &= (z4[i] == 0); pass1 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Zeroized word128 array\n"; #endif } //********** Non-zero'd block **********// { SecByteBlock z1(NULLPTR, 256); z1.SetMark(0); SecBlock<word32> z2(NULLPTR, 256); z2.SetMark(0); SecBlock<word64> z3(NULLPTR, 256); z3.SetMark(0); #if defined(CRYPTOPP_WORD128_AVAILABLE) SecBlock<word128> z4(NULLPTR, 256); z4.SetMark(0); #endif } //********** Assign **********// try { SecByteBlock a, b; temp = true; a.Assign((const byte*)"a", 1); b.Assign((const byte*)"b", 1); temp &= (a.SizeInBytes() == 1); temp &= (b.SizeInBytes() == 1); temp &= (a[0] == 'a'); temp &= (b[0] == 'b'); a.Assign((const byte*)"ab", 2); b.Assign((const byte*)"cd", 2); temp &= (a.SizeInBytes() == 2); temp &= (b.SizeInBytes() == 2); temp &= (a[0] == 'a' && a[1] == 'b'); temp &= (b[0] == 'c' && b[1] == 'd'); } catch(const Exception& /*ex*/) { temp = false; } pass2 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Assign byte\n"; try { SecBlock<word32> a, b; temp = true; word32 one[1] = {1}, two[1] = {2}; a.Assign(one, 1); b.Assign(two, 1); temp &= (a.SizeInBytes() == 4); temp &= (b.SizeInBytes() == 4); temp &= (a[0] == 1); temp &= (b[0] == 2); word32 three[2] = {1,2}, four[2] = {3,4}; a.Assign(three, 2); b.Assign(four, 2); temp &= (a.SizeInBytes() == 8); temp &= (b.SizeInBytes() == 8); temp &= (a[0] == 1 && a[1] == 2); temp &= (b[0] == 3 && b[1] == 4); } catch(const Exception& /*ex*/) { temp = false; } pass2 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Assign word32\n"; try { SecBlock<word64> a, b; temp = true; word64 one[1] = {1}, two[1] = {2}; a.Assign(one, 1); b.Assign(two, 1); temp &= (a.SizeInBytes() == 8); temp &= (b.SizeInBytes() == 8); temp &= (a[0] == 1); temp &= (b[0] == 2); word64 three[2] = {1,2}, four[2] = {3,4}; a.Assign(three, 2); b.Assign(four, 2); temp &= (a.SizeInBytes() == 16); temp &= (b.SizeInBytes() == 16); temp &= (a[0] == 1 && a[1] == 2); temp &= (b[0] == 3 && b[1] == 4); } catch(const Exception& /*ex*/) { temp = false; } pass2 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Assign word64\n"; #if defined(CRYPTOPP_WORD128_AVAILABLE) try { SecBlock<word128> a, b; temp = true; word128 one[1] = {1}, two[1] = {2}; a.Assign(one, 1); b.Assign(two, 1); temp &= (a.SizeInBytes() == 16); temp &= (b.SizeInBytes() == 16); temp &= (a[0] == 1); temp &= (b[0] == 2); word128 three[2] = {1,2}, four[2] = {3,4}; a.Assign(three, 2); b.Assign(four, 2); temp &= (a.SizeInBytes() == 32); temp &= (b.SizeInBytes() == 32); temp &= (a[0] == 1 && a[1] == 2); temp &= (b[0] == 3 && b[1] == 4); } catch(const Exception& /*ex*/) { temp = false; } pass2 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Assign word128\n"; #endif //********** Append **********// try { SecByteBlock a, b; temp = true; a.Assign((const byte*)"a", 1); b.Assign((const byte*)"b", 1); a += b; temp &= (a.SizeInBytes() == 2); temp &= (a[0] == 'a' && a[1] == 'b'); a.Assign((const byte*)"ab", 2); b.Assign((const byte*)"cd", 2); a += b; temp &= (a.SizeInBytes() == 4); temp &= (a[0] == 'a' && a[1] == 'b' && a[2] == 'c' && a[3] == 'd'); a.Assign((const byte*)"a", 1); a += a; temp &= (a.SizeInBytes() == 2); temp &= (a[0] == 'a' && a[1] == 'a'); a.Assign((const byte*)"ab", 2); a += a; temp &= (a.SizeInBytes() == 4); temp &= (a[0] == 'a' && a[1] == 'b' && a[2] == 'a' && a[3] == 'b'); } catch(const Exception& /*ex*/) { temp = false; } pass3 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Append byte\n"; try { SecBlock<word32> a, b; temp = true; const word32 one[1] = {1}, two[1] = {2}; a.Assign(one, 1); b.Assign(two, 1); a += b; temp &= (a.SizeInBytes() == 8); temp &= (a[0] == 1 && a[1] == 2); const word32 three[2] = {1,2}, four[2] = {3,4}; a.Assign(three, 2); b.Assign(four, 2); a += b; temp &= (a.SizeInBytes() == 16); temp &= (a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4); a.Assign(one, 1); a += a; temp &= (a.SizeInBytes() == 8); temp &= (a[0] == 1 && a[1] == 1); a.Assign(three, 2); a += a; temp &= (a.SizeInBytes() == 16); temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2); } catch(const Exception& /*ex*/) { temp = false; } pass3 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Append word32\n"; try { SecBlock<word64> a, b; temp = true; const word64 one[1] = {1}, two[1] = {2}; a.Assign(one, 1); b.Assign(two, 1); a += b; temp &= (a.SizeInBytes() == 16); temp &= (a[0] == 1 && a[1] == 2); const word64 three[2] = {1,2}, four[2] = {3,4}; a.Assign(three, 2); b.Assign(four, 2); a += b; temp &= (a.SizeInBytes() == 32); temp &= (a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4); a.Assign(one, 1); a += a; temp &= (a.SizeInBytes() == 16); temp &= (a[0] == 1 && a[1] == 1); a.Assign(three, 2); a += a; temp &= (a.SizeInBytes() == 32); temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2); } catch(const Exception& /*ex*/) { temp = false; } pass3 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Append word64\n"; #if defined(CRYPTOPP_WORD128_AVAILABLE) try { SecBlock<word128> a, b; temp = true; const word128 one[1] = {1}, two[1] = {2}; a.Assign(one, 1); b.Assign(two, 1); a += b; temp &= (a.SizeInBytes() == 32); temp &= (a[0] == 1 && a[1] == 2); const word128 three[2] = {1,2}, four[2] = {3,4}; a.Assign(three, 2); b.Assign(four, 2); a += b; temp &= (a.SizeInBytes() == 64); temp &= (a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4); a.Assign(one, 1); a += a; temp &= (a.SizeInBytes() == 32); temp &= (a[0] == 1 && a[1] == 1); a.Assign(three, 2); a += a; temp &= (a.SizeInBytes() == 64); temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2); } catch(const Exception& /*ex*/) { temp = false; } pass3 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Append word128\n"; #endif //********** Concatenate **********// // byte try { SecByteBlock a, b, c; temp = true; a.Assign((const byte*)"a", 1); b.Assign((const byte*)"b", 1); c = a + b; temp &= (a[0] == 'a'); temp &= (b[0] == 'b'); temp &= (c.SizeInBytes() == 2); temp &= (c[0] == 'a' && c[1] == 'b'); a.Assign((const byte*)"ab", 2); b.Assign((const byte*)"cd", 2); c = a + b; temp &= (a[0] == 'a' && a[1] == 'b'); temp &= (b[0] == 'c' && b[1] == 'd'); temp &= (c.SizeInBytes() == 4); temp &= (c[0] == 'a' && c[1] == 'b' && c[2] == 'c' && c[3] == 'd'); } catch(const Exception& /*ex*/) { temp = false; } pass4 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Concatenate byte\n"; // word32 try { SecBlock<word32> a, b, c; temp = true; const word32 one[1] = {1}, two[1] = {2}; a.Assign(one, 1); b.Assign(two, 1); c = a + b; temp &= (a[0] == 1); temp &= (b[0] == 2); temp &= (c.SizeInBytes() == 8); temp &= (c[0] == 1 && c[1] == 2); const word32 three[2] = {1,2}, four[2] = {3,4}; a.Assign(three, 2); b.Assign(four, 2); c = a + b; temp &= (a[0] == 1 && a[1] == 2); temp &= (b[0] == 3 && b[1] == 4); temp &= (c.SizeInBytes() == 16); temp &= (c[0] == 1 && c[1] == 2 && c[2] == 3 && c[3] == 4); } catch(const Exception& /*ex*/) { temp = false; } pass4 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Concatenate word32\n"; // word64 try { SecBlock<word64> a, b, c; temp = true; const word64 one[1] = {1}, two[1] = {2}; a.Assign(one, 1); b.Assign(two, 1); c = a + b; temp &= (a[0] == 1); temp &= (b[0] == 2); temp &= (c.SizeInBytes() == 16); temp &= (c[0] == 1 && c[1] == 2); const word64 three[2] = {1,2}, four[2] = {3,4}; a.Assign(three, 2); b.Assign(four, 2); c = a + b; temp &= (a[0] == 1 && a[1] == 2); temp &= (b[0] == 3 && b[1] == 4); temp &= (c.SizeInBytes() == 32); temp &= (c[0] == 1 && c[1] == 2 && c[2] == 3 && c[3] == 4); } catch(const Exception& /*ex*/) { temp = false; } pass4 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Concatenate word64\n"; #if defined(CRYPTOPP_WORD128_AVAILABLE) try { SecBlock<word128> a, b, c; temp = true; const word128 one[1] = {1}, two[1] = {2}; a.Assign(one, 1); b.Assign(two, 1); c = a + b; temp &= (a[0] == 1); temp &= (b[0] == 2); temp &= (c.SizeInBytes() == 32); temp &= (c[0] == 1 && c[1] == 2); const word128 three[2] = {1,2}, four[2] = {3,4}; a.Assign(three, 2); b.Assign(four, 2); c = a + b; temp &= (a[0] == 1 && a[1] == 2); temp &= (b[0] == 3 && b[1] == 4); temp &= (c.SizeInBytes() == 64); temp &= (c[0] == 1 && c[1] == 2 && c[2] == 3 && c[3] == 4); } catch(const Exception& /*ex*/) { temp = false; } pass4 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Concatenate word128\n"; #endif //********** Equality **********// // byte try { static const byte str1[] = "abcdefghijklmnopqrstuvwxyz"; static const byte str2[] = "zyxwvutsrqponmlkjihgfedcba"; static const byte str3[] = "0123456789"; temp = true; SecByteBlock a,b; a.Assign(str1, COUNTOF(str1)); b.Assign(str1, COUNTOF(str1)); temp &= (a.operator==(b)); a.Assign(str3, COUNTOF(str3)); b.Assign(str3, COUNTOF(str3)); temp &= (a == b); a.Assign(str1, COUNTOF(str1)); b.Assign(str2, COUNTOF(str2)); temp &= (a.operator!=(b)); a.Assign(str1, COUNTOF(str1)); b.Assign(str3, COUNTOF(str3)); temp &= (a != b); } catch(const Exception& /*ex*/) { temp = false; } pass5 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Equality byte\n"; // word32 try { static const word32 str1[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; static const word32 str2[] = {97,89,83,79,73,71,67,61,59,53,47,43,41,37,31,29,23,19,17,13,11,7,5,3,2}; static const word32 str3[] = {0,1,2,3,4,5,6,7,8,9}; temp = true; SecBlock<word32> a,b; a.Assign(str1, COUNTOF(str1)); b.Assign(str1, COUNTOF(str1)); temp &= (a.operator==(b)); a.Assign(str3, COUNTOF(str3)); b.Assign(str3, COUNTOF(str3)); temp &= (a == b); a.Assign(str1, COUNTOF(str1)); b.Assign(str2, COUNTOF(str2)); temp &= (a.operator!=(b)); a.Assign(str1, COUNTOF(str1)); b.Assign(str3, COUNTOF(str3)); temp &= (a != b); } catch(const Exception& /*ex*/) { temp = false; } pass5 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Equality word32\n"; // word64 try { static const word64 str1[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; static const word64 str2[] = {97,89,83,79,73,71,67,61,59,53,47,43,41,37,31,29,23,19,17,13,11,7,5,3,2}; static const word64 str3[] = {0,1,2,3,4,5,6,7,8,9}; temp = true; SecBlock<word64> a,b; a.Assign(str1, COUNTOF(str1)); b.Assign(str1, COUNTOF(str1)); temp &= (a.operator==(b)); a.Assign(str3, COUNTOF(str3)); b.Assign(str3, COUNTOF(str3)); temp &= (a == b); a.Assign(str1, COUNTOF(str1)); b.Assign(str2, COUNTOF(str2)); temp &= (a.operator!=(b)); a.Assign(str1, COUNTOF(str1)); b.Assign(str3, COUNTOF(str3)); temp &= (a != b); } catch(const Exception& /*ex*/) { temp = false; } pass5 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Equality word64\n"; #if defined(CRYPTOPP_WORD128_AVAILABLE) // word128 try { static const word128 str1[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; static const word128 str2[] = {97,89,83,79,73,71,67,61,59,53,47,43,41,37,31,29,23,19,17,13,11,7,5,3,2}; static const word128 str3[] = {0,1,2,3,4,5,6,7,8,9}; temp = true; SecBlock<word128> a,b; a.Assign(str1, COUNTOF(str1)); b.Assign(str1, COUNTOF(str1)); temp &= (a.operator==(b)); a.Assign(str3, COUNTOF(str3)); b.Assign(str3, COUNTOF(str3)); temp &= (a == b); a.Assign(str1, COUNTOF(str1)); b.Assign(str2, COUNTOF(str2)); temp &= (a.operator!=(b)); a.Assign(str1, COUNTOF(str1)); b.Assign(str3, COUNTOF(str3)); temp &= (a != b); } catch(const Exception& /*ex*/) { temp = false; } pass5 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Equality word128\n"; #endif //********** Allocator Size/Overflow **********// try { temp = false; AllocatorBase<word32> A; const size_t max = A.max_size(); SecBlock<word32> t(max+1); } catch(const Exception& /*ex*/) { temp = true; } catch(const std::exception& /*ex*/) { temp = true; } pass6 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Overflow word32\n"; try { temp = false; AllocatorBase<word64> A; const size_t max = A.max_size(); SecBlock<word64> t(max+1); } catch(const Exception& /*ex*/) { temp = true; } catch(const std::exception& /*ex*/) { temp = true; } pass6 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Overflow word64\n"; #if defined(CRYPTOPP_WORD128_AVAILABLE) try { temp = false; AllocatorBase<word128> A; const size_t max = A.max_size(); SecBlock<word128> t(max+1); } catch(const Exception& /*ex*/) { temp = true; } catch(const std::exception& /*ex*/) { temp = true; } pass6 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " Overflow word128\n"; #endif //********** FixedSizeAllocatorWithCleanup and Grow **********// // byte try { static const unsigned int SIZE = 8; SecBlockWithHint<byte, SIZE> block(SIZE); memset(block, 0xaa, block.SizeInBytes()); temp = true; block.CleanGrow(SIZE*2); temp &= (block.size() == SIZE*2); for (size_t i = 0; i < block.size()/2; i++) temp &= (block[i] == 0xaa); for (size_t i = block.size()/2; i < block.size(); i++) temp &= (block[i] == 0); block.CleanNew(SIZE*4); temp &= (block.size() == SIZE*4); for (size_t i = 0; i < block.size(); i++) temp &= (block[i] == 0); } catch(const Exception& /*ex*/) { temp = false; } catch(const std::exception& /*ex*/) { temp = false; } pass7 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " FixedSizeAllocator Grow with byte\n"; // word32 try { static const unsigned int SIZE = 8; SecBlockWithHint<word32, SIZE> block(SIZE); memset(block, 0xaa, block.SizeInBytes()); temp = true; block.CleanGrow(SIZE*2); temp &= (block.size() == SIZE*2); for (size_t i = 0; i < block.size()/2; i++) temp &= (block[i] == 0xaaaaaaaa); for (size_t i = block.size()/2; i < block.size(); i++) temp &= (block[i] == 0); block.CleanNew(SIZE*4); temp &= (block.size() == SIZE*4); for (size_t i = 0; i < block.size(); i++) temp &= (block[i] == 0); } catch(const Exception& /*ex*/) { temp = false; } catch(const std::exception& /*ex*/) { temp = false; } pass7 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " FixedSizeAllocator Grow with word32\n"; // word64 try { static const unsigned int SIZE = 8; SecBlockWithHint<word64, SIZE> block(SIZE); memset(block, 0xaa, block.SizeInBytes()); temp = true; block.CleanGrow(SIZE*2); temp &= (block.size() == SIZE*2); for (size_t i = 0; i < block.size()/2; i++) temp &= (block[i] == W64LIT(0xaaaaaaaaaaaaaaaa)); for (size_t i = block.size()/2; i < block.size(); i++) temp &= (block[i] == 0); block.CleanNew(SIZE*4); temp &= (block.size() == SIZE*4); for (size_t i = 0; i < block.size(); i++) temp &= (block[i] == 0); } catch(const Exception& /*ex*/) { temp = false; } catch(const std::exception& /*ex*/) { temp = false; } pass7 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " FixedSizeAllocator Grow with word64\n"; #if defined(CRYPTOPP_WORD128_AVAILABLE) // word128 try { static const unsigned int SIZE = 8; SecBlock<word128, AllocatorWithCleanup<word128, true> > block(SIZE); memset(block, 0xaa, block.SizeInBytes()); temp = true; block.CleanGrow(SIZE*2); temp &= (block.size() == SIZE*2); for (size_t i = 0; i < block.size()/2; i++) temp &= (block[i] == (((word128)W64LIT(0xaaaaaaaaaaaaaaaa) << 64U) | W64LIT(0xaaaaaaaaaaaaaaaa))); for (size_t i = block.size()/2; i < block.size(); i++) temp &= (block[i] == 0); block.CleanNew(SIZE*4); temp &= (block.size() == SIZE*4); for (size_t i = 0; i < block.size(); i++) temp &= (block[i] == 0); } catch(const Exception& /*ex*/) { temp = false; } catch(const std::exception& /*ex*/) { temp = false; } pass7 &= temp; if (!temp) std::cout << "FAILED:"; else std::cout << "passed:"; std::cout << " FixedSizeAllocator Grow with word128\n"; #endif return pass1 && pass2 && pass3 && pass4 && pass5 && pass6 && pass7; }