TEST(IndexTests, BasicTest) { auto pool = TestingHarness::GetInstance().GetTestingPool(); std::vector<ItemPointer> locations; // INDEX std::unique_ptr<index::Index> index(BuildIndex()); std::unique_ptr<storage::Tuple> key0(new storage::Tuple(key_schema, true)); key0->SetValue(0, ValueFactory::GetIntegerValue(100), pool); key0->SetValue(1, ValueFactory::GetStringValue("a"), pool); // INSERT index->InsertEntry(key0.get(), item0); locations = index->ScanKey(key0.get()); EXPECT_EQ(locations.size(), 1); EXPECT_EQ(locations[0].block, item0.block); // DELETE index->DeleteEntry(key0.get(), item0); locations = index->ScanKey(key0.get()); EXPECT_EQ(locations.size(), 0); delete tuple_schema; }
// DELETE HELPER FUNCTION void DeleteTest(index::Index *index, VarlenPool *pool, size_t scale_factor) { // Loop based on scale factor for (size_t scale_itr = 1; scale_itr <= scale_factor; scale_itr++) { // Delete a bunch of keys based on scale itr std::unique_ptr<storage::Tuple> key0(new storage::Tuple(key_schema, true)); std::unique_ptr<storage::Tuple> key1(new storage::Tuple(key_schema, true)); std::unique_ptr<storage::Tuple> key2(new storage::Tuple(key_schema, true)); std::unique_ptr<storage::Tuple> key3(new storage::Tuple(key_schema, true)); std::unique_ptr<storage::Tuple> key4(new storage::Tuple(key_schema, true)); key0->SetValue(0, ValueFactory::GetIntegerValue(100 * scale_itr), pool); key0->SetValue(1, ValueFactory::GetStringValue("a"), pool); key1->SetValue(0, ValueFactory::GetIntegerValue(100 * scale_itr), pool); key1->SetValue(1, ValueFactory::GetStringValue("b"), pool); key2->SetValue(0, ValueFactory::GetIntegerValue(100 * scale_itr), pool); key2->SetValue(1, ValueFactory::GetStringValue("c"), pool); key3->SetValue(0, ValueFactory::GetIntegerValue(400 * scale_itr), pool); key3->SetValue(1, ValueFactory::GetStringValue("d"), pool); key4->SetValue(0, ValueFactory::GetIntegerValue(500 * scale_itr), pool); key4->SetValue(1, ValueFactory::GetStringValue("e"), pool); // DELETE index->DeleteEntry(key0.get(), item0); index->DeleteEntry(key1.get(), item1); // index->DeleteEntry(key2.get(), item2); index->DeleteEntry(key3.get(), item1); index->DeleteEntry(key3.get(), item1); index->DeleteEntry(key3.get(), item1); index->DeleteEntry(key4.get(), item1); index->DeleteEntry(key4.get(), item1); index->DeleteEntry(key4.get(), item1); LOG_INFO("--------------- next round delete ---------------"); } }
InitRegistry::InitRegistry() { try { RegistryKey key0(HKEY_CURRENT_USER); RegistryKey key1 = key0.createOrOpenPath(registryEntry); } catch(Exception) { // ignore } }
bool LRSPublicKey::VerifyKey(AsymmetricKey &key) const { if(key.IsPrivateKey() ^ !IsPrivateKey()) { return false; } QSharedPointer<AsymmetricKey> key0(GetPublicKey()); QSharedPointer<AsymmetricKey> key1(key.GetPublicKey()); return key0 == key1; }
TEST(IndexTests, DeleteTest) { auto pool = TestingHarness::GetInstance().GetTestingPool(); std::vector<ItemPointer> locations; // INDEX std::unique_ptr<index::Index> index(BuildIndex()); // Single threaded test size_t scale_factor = 1000; LaunchParallelTest(1, InsertTest, index.get(), pool, scale_factor); LaunchParallelTest(1, DeleteTest, index.get(), pool, scale_factor); // Checks std::unique_ptr<storage::Tuple> key0(new storage::Tuple(key_schema, true)); std::unique_ptr<storage::Tuple> key1(new storage::Tuple(key_schema, true)); std::unique_ptr<storage::Tuple> key2(new storage::Tuple(key_schema, true)); key0->SetValue(0, ValueFactory::GetIntegerValue(100), pool); key0->SetValue(1, ValueFactory::GetStringValue("a"), pool); key1->SetValue(0, ValueFactory::GetIntegerValue(100), pool); key1->SetValue(1, ValueFactory::GetStringValue("b"), pool); key2->SetValue(0, ValueFactory::GetIntegerValue(100), pool); key2->SetValue(1, ValueFactory::GetStringValue("c"), pool); locations = index->ScanKey(key0.get()); EXPECT_EQ(locations.size(), 0); locations = index->ScanKey(key1.get()); if (index->HasUniqueKeys()) EXPECT_EQ(locations.size(), 0); else EXPECT_EQ(locations.size(), 2); locations = index->ScanKey(key2.get()); EXPECT_EQ(locations.size(), 1); EXPECT_EQ(locations[0].block, item1.block); locations = index->ScanAllKeys(); if (index->HasUniqueKeys()) EXPECT_EQ(locations.size(), scale_factor); else EXPECT_EQ(locations.size(), 3 * scale_factor); delete tuple_schema; }
bool GrPath::isEqualTo(const SkPath& path, const GrStyle& style) const { // Since this is only called in debug we don't care about performance. int cnt0 = GrStyle::KeySize(fStyle, GrStyle::Apply::kPathEffectAndStrokeRec); int cnt1 = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec); if (cnt0 < 0 || cnt1 < 0 || cnt0 != cnt1) { return false; } if (cnt0) { SkAutoTArray<uint32_t> key0(cnt0); SkAutoTArray<uint32_t> key1(cnt0); write_style_key(key0.get(), fStyle); write_style_key(key1.get(), style); if (0 != memcmp(key0.get(), key1.get(), cnt0)) { return false; } } return fSkPath == path; }
// DELETE HELPER FUNCTION void DeleteTest2(index::Index *index, VarlenPool *pool, size_t scale_factor) { // Loop based on scale factor for (size_t scale_itr = 1; scale_itr <= scale_factor; scale_itr++) { // Delete a bunch of keys based on scale itr std::unique_ptr<storage::Tuple> key0(new storage::Tuple(key_schema, true)); std::unique_ptr<storage::Tuple> key1(new storage::Tuple(key_schema, true)); key0->SetValue(0, ValueFactory::GetIntegerValue(100 * scale_itr), pool); key0->SetValue(1, ValueFactory::GetStringValue("a"), pool); key1->SetValue(0, ValueFactory::GetIntegerValue(100 * scale_itr), pool); key1->SetValue(1, ValueFactory::GetStringValue("b"), pool); // DELETE index->InsertEntry(key1.get(), item0); index->InsertEntry(key1.get(), item1); index->DeleteEntry(key1.get(), item0); index->DeleteEntry(key1.get(), item1); index->DeleteEntry(key1.get(), item1); } }
// If either id is different or the clip or the matrix are different the // cached image won't be found. Even if it is caching the same bitmap. static void test_dont_find_if_diff_key(skiatest::Reporter* reporter, const sk_sp<SkSpecialImage>& image, const sk_sp<SkSpecialImage>& subset) { static const size_t kCacheSize = 1000000; SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCacheSize)); SkIRect clip1 = SkIRect::MakeWH(100, 100); SkIRect clip2 = SkIRect::MakeWH(200, 200); SkImageFilter::Cache::Key key0(0, SkMatrix::I(), clip1, image->uniqueID(), image->subset()); SkImageFilter::Cache::Key key1(1, SkMatrix::I(), clip1, image->uniqueID(), image->subset()); SkImageFilter::Cache::Key key2(0, SkMatrix::MakeTrans(5, 5), clip1, image->uniqueID(), image->subset()); SkImageFilter::Cache::Key key3(0, SkMatrix::I(), clip2, image->uniqueID(), image->subset()); SkImageFilter::Cache::Key key4(0, SkMatrix::I(), clip1, subset->uniqueID(), subset->subset()); SkIPoint offset = SkIPoint::Make(3, 4); cache->set(key0, image.get(), offset); SkIPoint foundOffset; REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset)); REPORTER_ASSERT(reporter, !cache->get(key2, &foundOffset)); REPORTER_ASSERT(reporter, !cache->get(key3, &foundOffset)); REPORTER_ASSERT(reporter, !cache->get(key4, &foundOffset)); }
int main() { int i,k,ipl_mode=1; //UINT r; // Initialize Disk I/F and ROM System_Initialize(); /* Event loop never exits. */ while (1){ // IPL if(ipl_mode==1){ // System Program Load IPL(); // Start MZ MZ_release(); ipl_mode=0; } // CMT Control if((z80_sts.status&S_CMT)==S_CMT){ z80_sts.status&=~S_CMT; // Eject and Set Tape if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_OPEN)==C_OPEN){ IOWR_8DIRECT(REG_BASE, MZ_CMT_STATUS, C_OPEN); tape_unmount(); fname[0]='\0'; key0(settape); z80_sts.status|=S_FBTN; // Set Flag MZ_Brequest(); menu_process(); MZ_Brelease(); z80_sts.status&=~S_FBTN; // Clear Flag } // Load if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_PLAY)==C_PLAY){ IOWR_8DIRECT(REG_BASE, MZ_CMT_STATUS, C_PLAY); IOWR_8DIRECT(REG_BASE, MZ_CMT_CTRL, C_MTON+C_TAPE); // Motor On cmtload(); } // Rewind if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_REW)==C_REW){ if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_APSS)==C_APSS){ apss_r(); } else { tape_rewind(); IOWR_8DIRECT(REG_BASE, MZ_CMT_STATUS, C_REW); } } // F.Forward if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_FF)==C_FF){ if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_APSS)==C_APSS){ apss_f(); } else { IOWR_8DIRECT(REG_BASE, MZ_CMT_STATUS, C_FF); } } } // Function Button if((z80_sts.status&S_FBTN)==S_FBTN){ MZ_Brequest(); menu_process(); MZ_Brelease(); z80_sts.status&=~S_FBTN; } // BST check if((IORD_8DIRECT(REG_BASE, MZ_SYS_STATUS)&S_BST)==S_BST){ ipl_mode=1; } // Quick Load/Save // if((z80_sts.status&0x02)==0x02){ // if(IORD(CMT_0_BASE, 3)==0x0f){ // CMD is Load // IOWR(CMT_0_BASE, 2, 0x80); // set STAT busy // Wait for confirm busy by Z80 // while(IORD(CMT_0_BASE, 3)!=0); // if(tname[0]=='\0'){ // if tape file is empty // z80_sts.status=0x03; // // Z80-Bus request // MZ_Brequest(); // key0(settape); // k=menu(0,0,0); // Root menu // // Z80-Bus release // MZ_Brelease(); // z80_sts.status=0x02; // if(k!=10){ // z80_sts.status=0; // IOWR(CMT_0_BASE, 2, 0xff); // set STAT error // continue; // } // //keybuf_clear(); // strcpy(tname, fname); // IOWR(CMT_0_BASE, 1, 1); // ql_pt=0; // } // quick_load(); // IOWR(CMT_0_BASE, 2, 0); // set STAT free // z80_sts.status&=0xfffffffd; // } // if(IORD(CMT_0_BASE, 3)==0xf0){ // CMD is Save // IOWR(CMT_0_BASE, 2, 0x80); // set STAT busy // // Wait for confirm busy by Z80 // while(IORD(CMT_0_BASE, 3)!=0); // if(tname[0]=='\0'){ // if tape file is empty // // Z80-Bus request // MZ_Brequest(); // i=input_file_name(); // // Z80-Bus release // MZ_Brelease(); // if(tname[0]=='\0'||i<0){ // z80_sts.status=0; // IOWR(CMT_0_BASE, 2, 0xff); // set STAT error // continue; // } // keybuf_clear(); // IOWR(CMT_0_BASE, 1, 1); // } // if(quick_save()!=FR_OK) // IOWR(CMT_0_BASE, 2, 0xff); // set STAT error // else // IOWR(CMT_0_BASE, 2, 0); // set STAT free // z80_sts.status&=0xfffffffd; // } // } } return 0; }
/* * IPL Emulation(CMT only) */ int IPL_from_tape(void) { UINT size; unsigned char k; MZ_cls(); t_block=0; // Select Tape file if(tname[0]=='\0'){ MZ_msg(10,0,"Make Ready CMT"); do{ k=get_key(); if((k&'C')=='C'){ key0(settape); z80_sts.status|=S_FBTN; // Set Flag }else if(k==0x1b&&!(IORD_8DIRECT(REG_BASE, MZ_SYS_SW70)&0x10)){ return -1; }else if((z80_sts.status&S_FBTN)!=S_FBTN){ continue; } SaveVRAM(); menu_process(); z80_sts.status&=~S_FBTN; // Clear Flag RestoreVRAM(); }while(fname[0]=='\0'); tape_mount(); } while(1){ // File Read MZ_msg(4,0,"IPL is looking for a program"); usleep(500000); tape_rdinf_bulk(&MZ80B_MEM(0x4f00)); MZ_cls(); MZ_msg(0,0,"IPL is loading "); MZ_msgx(16,0,(char *)&MZ80B_MEM(0x4f01),16); if((MZ80B_MEM(0x4f00))==0x01) break; MZ_cls(); MZ_msg(10,0,"File Mode error"); tape_unmount(); fname[0]='\0'; if(!(IORD_8DIRECT(REG_BASE, MZ_SYS_SW70)&0x10)) return -1; MZ_msg(4,2,"Pressing S key starts the CMT"); while(1){ if((get_key()&'S')=='S'){ if(fname[0]!='\0') break; }else if((z80_sts.status&S_FBTN)==S_FBTN){ SaveVRAM(); menu_process(); z80_sts.status&=~S_FBTN; // Clear Flag RestoreVRAM(); } } MZ_cls(); } size=(MZ80B_MEM(0x4f13)<<8)+MZ80B_MEM(0x4f12); tape_rddat_bulk(&MZ80B_MEM(0),size); return 0; }
double LWEnvelope::Evaluate(double Time) { if ( NumKeys == 0 ) return 0.0; if ( NumKeys == 1 ) return Keys.begin()->value; if(InternalCalculation) { float offset=0.0; if (Time>EndTime) Time=EndTime; if (Time<StartTime) Time=StartTime; /* get the endpoints of the interval being evaluated */ std::list<LWKey>::iterator key0(Keys.begin()); std::list<LWKey>::iterator key1(Keys.begin()); while ( Time > (*(++key1)).Time ) // Hope this construction works! { key0 = key1; } /* check for singularities first */ if ( Time == (*key0).Time ) return (*key0).value + offset; else if ( Time == (*key1).Time ) return (*key1).value + offset; /* get interval length, time in [0, 1] */ float t = ( Time - (*key0).Time ) / ( (*key1).Time - (*key0).Time ); float out=0.0; float in=0.0; float h1,h2,h3,h4; switch ( (*key1).shape ) { case SHAPE_TCB: case SHAPE_BEZI: case SHAPE_HERM: out = outgoing( key0, key1 ); in = incoming( key0, key1 ); hermite( t, &h1, &h2, &h3, &h4 ); return h1 * (*key0).value + h2 * (*key1).value + h3 * out + h4 * in + offset; case SHAPE_BEZ2: return 0.0;//bez2( key0, key1, time ) + offset; case SHAPE_LINE: return (*key0).value + t * ( (*key1).value - (*key0).value ) + offset; case SHAPE_STEP: return (*key0).value + offset; default: return offset; } double TheResult=1.0; return TheResult;//Lightwave3D::chaninfo->channelEvaluate(EnvChannel,Time); } else return Lightwave3D::chaninfo->channelEvaluate(EnvChannel,Time); }
//////////////////////////////////////////////////////////////////////// // constructor: reads in the *.lev file and builds basic data structure // for the gate-level ckt //////////////////////////////////////////////////////////////////////// circuit::circuit(char *cktName) { FILE *inFile; char fName[40]; int i, j, count; char c; int gatenum, junk; int f1, f2, f3; strcpy(fName, cktName); strcat(fName, ".lev"); inFile = fopen(fName, "r"); if (inFile == NULL) { fprintf(stderr, "Can't open .lev file\n"); exit(-1); } numgates = maxlevels = 0; numInputs = numOutputs = 0; fscanf(inFile, "%d", &count); // number of gates fscanf(inFile, "%d", &junk); // skip the second line printf("Reading in gate information...\n"); // allocate space for gates data structure gtype = new unsigned char[count]; fanin = new short[count]; fanout = new short[count]; levelNum = new int[count]; faninlist = new int * [count]; fanoutlist = new int * [count]; // now read in the circuit for (i=1; i<count; i++) { fscanf(inFile, "%d", &gatenum); fscanf(inFile, "%d", &f1); fscanf(inFile, "%d", &f2); fscanf(inFile, "%d", &f3); numgates++; gtype[gatenum] = (unsigned char) f1; if (gtype[gatenum] == G_INPUT) numInputs++; else if (gtype[gatenum] == G_OUTPUT){ numOutputs++; outputGate.push_back(gatenum); } else if (gtype[gatenum] > 13) printf("gate %d is an unimplemented gate type\n", gatenum); f2 = (int) f2; levelNum[gatenum] = f2; if (f2 >= (maxlevels)) maxlevels = f2 + 5; fanin[gatenum] = (int) f3; // now read in the faninlist faninlist[gatenum] = new int[fanin[gatenum]]; for (j=0; j<fanin[gatenum]; j++) { fscanf(inFile, "%d", &f1); faninlist[gatenum][j] = (int) f1; } for (j=0; j<fanin[gatenum]; j++) // followed by samethings fscanf(inFile, "%d", &junk); // read in the fanout list fscanf(inFile, "%d", &f1); fanout[gatenum] = (int) f1; fanoutlist[gatenum] = new int[fanout[gatenum]]; for (j=0; j<fanout[gatenum]; j++) { fscanf(inFile, "%d", &f1); fanoutlist[gatenum][j] = (int) f1; } // skip till end of line while ((c = getc(inFile)) != '\n' && c != EOF); } // for (i...) fclose(inFile); printf("Successfully read in circuit:\n"); printf("\t%d PIs.\n", numInputs); printf("\t%d POs.\n", numOutputs); printf("\t%d total number of gates\n", numgates); printf("\t%d levels in the circuit.\n", maxlevels / 5); //SET ITE OPERATIONS //Adding Terminal Nodes to Unique Table uniqueTable.push_back(0); uniqueTable.push_back(new int[3]); uniqueTable[1][0] = 1; uniqueTable[1][1] = 1; uniqueTable[1][2] = 1; uniqueTable.push_back( new int[3]); uniqueTable[2][0] = 2; uniqueTable[2][1] = 2; uniqueTable[2][2] = 2; std::vector<int> key0 (3,1); std::vector<int> key1 (3,2); hashUT[key0] = 1; hashUT[key1] = 2; //Offset Gate by 1 gateNode.push_back(0); //Adding Inputs to Unique Table for(int i = 3; i < numInputs+3; i++){ uniqueTable.push_back(new int[3]); uniqueTable[i][2] = i-2; uniqueTable[i][1] = 2; uniqueTable[i][0] = 1; int keys[] = {i-2, 2, 1}; std::vector<int> key (keys, keys + sizeof(keys) / sizeof(int)); hashUT[key] = i; gateNode.push_back(i); } }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Calculate the codes length // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void huffmanTable::calcHuffmanCodesLength(const imbxUint32 maxCodeLength) { PUNTOEXE_FUNCTION_START(L"huffmanTable::calcHuffmanCodesLength"); // Order the values by their frequency typedef std::map<huffmanTable::freqValue, bool, huffmanTable::freqValueCompare> tFreqOrderedMap; tFreqOrderedMap freqOrderedValues; for(size_t scanValues = 0; scanValues < m_valuesFreq.size(); ++scanValues) { if(m_valuesFreq[scanValues].m_freq != 0) { huffmanTable::freqValue key(m_valuesFreq[scanValues].m_freq, (imbxUint32)scanValues); freqOrderedValues[key] = true; } } while(freqOrderedValues.size() > 1) { huffmanTable::freqValue key0(freqOrderedValues.begin()->first); freqOrderedValues.erase(freqOrderedValues.begin()); huffmanTable::freqValue key1(freqOrderedValues.begin()->first); freqOrderedValues.erase(freqOrderedValues.begin()); key0.m_freq += key1.m_freq; m_valuesFreq[key0.m_value].m_freq = key0.m_freq; m_valuesFreq[key1.m_value].m_freq = 0; m_valuesFreq[key0.m_value].m_codeLength++; freqOrderedValues[key0] = true; imbxUint32 chainedValue; for(chainedValue = key0.m_value; m_valuesFreq[chainedValue].m_nextCode != -1; /* empty */) { chainedValue = (imbxUint32)m_valuesFreq[chainedValue].m_nextCode; m_valuesFreq[chainedValue].m_codeLength++; } m_valuesFreq[chainedValue].m_nextCode = key1.m_value; while(m_valuesFreq[chainedValue].m_nextCode != -1) { chainedValue = (imbxUint32)m_valuesFreq[chainedValue].m_nextCode; m_valuesFreq[chainedValue].m_codeLength++; } } typedef std::map<huffmanTable::lengthValue, bool, huffmanTable::lengthValueCompare> tLengthOrderedMap; tLengthOrderedMap lengthOrderedValues ; for(size_t findValuesPerLength = 0; findValuesPerLength < m_valuesFreq.size(); ++findValuesPerLength) { if(m_valuesFreq[findValuesPerLength].m_codeLength != 0) { huffmanTable::lengthValue key(m_valuesFreq[findValuesPerLength].m_codeLength, (imbxUint32)findValuesPerLength); lengthOrderedValues[key] = true; m_valuesPerLength[m_valuesFreq[findValuesPerLength].m_codeLength]++; } } long insertPosition = 0; for(tLengthOrderedMap::iterator scanLengths = lengthOrderedValues.begin(); scanLengths != lengthOrderedValues.end(); ++scanLengths) { m_orderedValues[insertPosition++] = scanLengths->first.m_value; } // Reduce the size of the codes' lengths for(imbxUint32 reduceLengths=sizeof(m_valuesPerLength)/sizeof(m_valuesPerLength[0]) - 1; reduceLengths>maxCodeLength; --reduceLengths) { while(m_valuesPerLength[reduceLengths] != 0) { imbxInt32 reduceLengths1; for(reduceLengths1=reduceLengths-2; reduceLengths1 != -1 && m_valuesPerLength[reduceLengths1] == 0; --reduceLengths1){} if(reduceLengths1==-1) { break; } m_valuesPerLength[reduceLengths]-=2; m_valuesPerLength[reduceLengths-1]++; m_valuesPerLength[reduceLengths1+1]+=2; m_valuesPerLength[reduceLengths1]--; } } // Find the first available length for(m_firstValidLength = 1; m_firstValidLength != sizeof(m_valuesPerLength) / sizeof(m_valuesPerLength[0]); ++m_firstValidLength) { if(m_valuesPerLength[m_firstValidLength] != 0) { break; } } PUNTOEXE_FUNCTION_END(); }
void AsymmetricKeyFail(Library *lib) { CppRandom rng; QByteArray data(1500, 0); rng.GenerateBlock(data); QByteArray small_data(10, 0); rng.GenerateBlock(small_data); QByteArray empty; QScopedPointer<AsymmetricKey> key0(lib->CreatePrivateKey()); QScopedPointer<AsymmetricKey> key1(lib->CreatePrivateKey()); EXPECT_TRUE(key0->IsValid()); EXPECT_TRUE(key1->IsValid()); EXPECT_TRUE(key0->Decrypt(data).isEmpty()); EXPECT_TRUE(key1->Decrypt(small_data).isEmpty()); EXPECT_TRUE(key1->Decrypt(empty).isEmpty()); QByteArray ciphertext = key0->Encrypt(data); EXPECT_TRUE(key1->Decrypt(ciphertext).isEmpty()); ciphertext = key1->Encrypt(empty); EXPECT_EQ(key1->Decrypt(ciphertext), empty); QByteArray sig = key1->Sign(data); EXPECT_TRUE(key1->Verify(data, sig)); EXPECT_FALSE(key0->Verify(data, sig)); sig = key1->Sign(small_data); EXPECT_TRUE(key1->Verify(small_data, sig)); EXPECT_FALSE(key0->Verify(small_data, sig)); sig = key1->Sign(empty); EXPECT_TRUE(key1->Verify(empty, sig)); EXPECT_FALSE(key0->Verify(empty, sig)); EXPECT_FALSE(key0->Verify(data, empty)); EXPECT_FALSE(key0->Verify(data, small_data)); EXPECT_FALSE(key0->Verify(data, data)); key1.reset(lib->LoadPrivateKeyFromByteArray(data)); EXPECT_TRUE(!key1->IsValid()); EXPECT_TRUE(key1->Encrypt(data).isEmpty()); EXPECT_TRUE(key1->Decrypt(key1->Encrypt(data)).isEmpty()); EXPECT_FALSE(key1->Verify(data, key1->Sign(data))); QScopedPointer<AsymmetricKey> empty_key(key1->GetPublicKey()); EXPECT_TRUE(empty_key.isNull()); QString filename = "test_private_key_load"; EXPECT_FALSE(QFile(filename).exists()); key1.reset(lib->LoadPrivateKeyFromFile(filename)); EXPECT_TRUE(!key1->IsValid()); EXPECT_TRUE(key1->Encrypt(data).isEmpty()); EXPECT_TRUE(key1->Decrypt(key1->Encrypt(data)).isEmpty()); EXPECT_FALSE(key1->Verify(data, key1->Sign(data))); empty_key.reset(key1->GetPublicKey()); EXPECT_TRUE(empty_key.isNull()); key1.reset(lib->LoadPublicKeyFromByteArray(data)); EXPECT_TRUE(!key1->IsValid()); EXPECT_TRUE(key1->Encrypt(data).isEmpty()); EXPECT_TRUE(key1->Decrypt(key1->Encrypt(data)).isEmpty()); EXPECT_FALSE(key1->Verify(data, key1->Sign(data))); empty_key.reset(key1->GetPublicKey()); EXPECT_TRUE(empty_key.isNull()); key1.reset(lib->LoadPublicKeyFromFile(filename)); EXPECT_TRUE(!key1->IsValid()); EXPECT_TRUE(key1->Encrypt(data).isEmpty()); EXPECT_TRUE(key1->Decrypt(key1->Encrypt(data)).isEmpty()); EXPECT_FALSE(key1->Verify(data, key1->Sign(data))); empty_key.reset(key1->GetPublicKey()); EXPECT_TRUE(empty_key.isNull()); }