MStatus exampleCameraSetViewCmd::doEditFlags() // // Description: // Handle edits for flags added by this class. // If the flag is unknown, return MS::kSuccess and the parent class // will attempt to process the flag. Returning MS::kUnknownParameter // will cause the parent class to process the flag. // { MPx3dModelView *user3dModelView = modelView(); if (NULL == user3dModelView) { MGlobal::displayError("NULL == user3dModelView!"); return MS::kFailure; } // This is now safe to do, since the above test passed. // exampleCameraSetView *dView = (exampleCameraSetView *)user3dModelView; MArgParser argData = parser(); if (argData.isFlagSet(kTestMultiPackInitFlag)) { return initTests(*dView); } else if (argData.isFlagSet(kTestMultiPackResultsFlag)) { return testResults(*dView); } else if (argData.isFlagSet(kTestMultiPackClearFlag)) { return clearResults(*dView); } return MS::kUnknownParameter; }
App::App(QCoreApplication *application, const QString &sessionName) : m_app(application) , m_exitCode(0) , m_closed(false) { QString session("copyq"); if ( !sessionName.isEmpty() ) { session += "-" + sessionName; m_app->setProperty( "CopyQ_session_name", QVariant(sessionName) ); } QCoreApplication::setOrganizationName(session); QCoreApplication::setApplicationName(session); #ifdef HAS_TESTS initTests(); #endif #ifdef Q_OS_UNIX if ( !UnixSignalHandler::create(m_app.data()) ) log( QString("Failed to create handler for Unix signals!"), LogError ); #endif createPlatformNativeInterface()->loadSettings(); installTranslator(); #ifdef HAS_TESTS initTestsSettings(); #endif }
App::App(QCoreApplication *application, const QString &sessionName) : m_app(application) , m_exitCode(0) , m_started(false) , m_closed(false) { QString session("copyq"); if ( !sessionName.isEmpty() ) { session += "-" + sessionName; m_app->setProperty( "CopyQ_session_name", QVariant(sessionName) ); } qputenv("COPYQ_SESSION_NAME", sessionName.toUtf8()); qputenv("COPYQ", QCoreApplication::applicationFilePath().toUtf8()); QCoreApplication::setOrganizationName(session); QCoreApplication::setApplicationName(session); #ifdef HAS_TESTS initTests(); #endif #ifdef Q_OS_UNIX if ( !UnixSignalHandler::create(m_app.data()) ) log( QString("Failed to create handler for Unix signals!"), LogError ); #endif }
int main(void) { int i; initTests(__FILE__); initWalletTest(); initWallet(); printf("Listing wallets...\n"); SEND_ONE_TEST_STREAM(test_stream_list_wallets); printf("Creating new wallet...\n"); SEND_ONE_TEST_STREAM(test_stream_new_wallet); printf("Listing wallets...\n"); SEND_ONE_TEST_STREAM(test_stream_list_wallets); for(i = 0; i < 4; i++) { printf("Creating new address...\n"); SEND_ONE_TEST_STREAM(test_stream_new_address); } printf("Getting number of addresses...\n"); SEND_ONE_TEST_STREAM(test_stream_get_num_addresses); printf("Getting address 1...\n"); SEND_ONE_TEST_STREAM(test_stream_get_address1); printf("Getting address 0...\n"); SEND_ONE_TEST_STREAM(test_stream_get_address0); printf("Signing transaction...\n"); SEND_ONE_TEST_STREAM(test_stream_sign_tx); printf("Signing transaction again...\n"); SEND_ONE_TEST_STREAM(test_stream_sign_tx); //printf("Formatting...\n"); //SEND_ONE_TEST_STREAM(test_stream_format); printf("Loading wallet using incorrect key...\n"); SEND_ONE_TEST_STREAM(test_stream_load_incorrect); printf("Loading wallet using correct key...\n"); SEND_ONE_TEST_STREAM(test_stream_load_correct); printf("Changing wallet key...\n"); SEND_ONE_TEST_STREAM(test_stream_change_key); printf("Unloading wallet...\n"); SEND_ONE_TEST_STREAM(test_stream_unload); printf("Loading wallet using changed key...\n"); SEND_ONE_TEST_STREAM(test_stream_load_with_changed_key); printf("Changing name...\n"); SEND_ONE_TEST_STREAM(test_stream_change_name); printf("Listing wallets...\n"); SEND_ONE_TEST_STREAM(test_stream_list_wallets); finishTests(); exit(0); }
App::App(int argc, char** argv) : m_mf(nullptr) , m_failedTests(0) { if( !parseCommandLineArguments(argc, argv) ) { return; } if( !initTests() ) { return; } test(); }
bool atWrapper::runAutoTests() { //SVG needs this widget... QWidget dummy; bool haveBaseline = false; if (!initTests(&haveBaseline)) return false; executeTests(); if ( !haveBaseline ) { qDebug( " First run! Creating baseline..." ); createBaseline(); } else { qDebug( " Comparing results..." ); compare(); } return true; }
int IndieLib() { #ifdef PLATFORM_WIN32 //memory leaks for win32 creation FINDMEMLEAK(-1); //When you find a mem. leak, refer to the number displayed in the console and put it here to break when it is created #endif // ----- IndieLib intialization ----- CIndieLib *mI = CIndieLib::instance(); if (!mI->init()) return 0; //Sets the working path as the 'exe' directory. All resource paths are relative to this directory if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) { std::cout<<"\nUnable to Set the working path !"; } // ----- Fcn pointer tests initialization ----- initTests(); testsvectoriterator itr; //LOOP - Prepare Permanent tests for (itr = g_permanenttests.begin(); itr != g_permanenttests.end(); ++itr) { (*itr)->prepareTests(); }//LOOP END //LOOP - Prepare Temporary tests for (itr = g_tests.begin(); itr != g_tests.end(); ++itr) { (*itr)->prepareTests(); }//LOOP END // ----- Main Loop ----- g_mainTimer.start(); double ticks = g_mainTimer.getTicks(); double pastticks = g_mainTimer.getTicks(); testsvectoriterator currentTest = g_tests.begin(); (*currentTest)->setActive(true); while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit()) { // ----- Input Update ---- mI->_input->update(); // -------- Render ------- mI->_render->clearViewPort(0,0,0); mI->_render->beginScene(); //LOOP - Permanent Tests for (itr = g_permanenttests.begin(); itr != g_permanenttests.end(); ++itr) { (*itr)->performTests(static_cast<float>(ticks - pastticks)); }//LOOP END //LOOP - Tests for (itr = g_tests.begin(); itr != g_tests.end(); ++itr) { (*itr)->performTests(static_cast<float>(ticks - pastticks)); }//LOOP END mI->_entity2dManager->renderEntities2d(); //Entities rendering mI->_entity2dManager->renderGridAreas(g_gridcolorR,g_gridcolorG,g_gridcolorB,g_gridcolorA); //Grid areas rendering (on top of it) can be disabled per entity mI->_entity2dManager->renderCollisionAreas(g_collisionColorR,g_collisionColorG,g_collisionColorB,g_collisionColorA); //Collision areas rendering (on top of it) can be disabled per entity mI->_render->endScene(); //mI->_render->showFpsInWindowTitle(); pastticks = ticks; ticks += g_mainTimer.getTicks(); //Perform next test setup (if needed) Arrow keys change current temporary test using if (mI->_input->onKeyPress(IND_KEYRIGHT) && !mI->_input->onKeyPress(IND_KEYLEFT)){ //Current test is not active (*currentTest)->setActive(false); currentTest++; //IF - Check limits if(currentTest == g_tests.end()){ currentTest = g_tests.begin(); } //Next test is active (*currentTest)->setActive(true); } else if (mI->_input->onKeyPress(IND_KEYLEFT) && !mI->_input->onKeyPress(IND_KEYRIGHT)){ //Current test is not active (*currentTest)->setActive(false); //Decrement (taking into account limits) if(currentTest == g_tests.begin()){ currentTest = g_tests.end(); } currentTest--; //Next test is active (*currentTest)->setActive(true); } } // ----- Indielib End ----- releaseTests(); mI->end(); return 0; }
/** A proper test suite for randomness would be quite big, so this test * spits out samples into random.dat, where they can be analysed using * an external program. */ int main(int argc, char **argv) { uint8_t r[32]; int i, j; int num_samples; int abort; unsigned int bytes_written; FILE *f; uint8_t seed[64]; uint8_t keys[64][32]; uint8_t key2[32]; initTests(__FILE__); // Before outputting samples, do a sanity check that // generateDeterministic256() actually has different outputs when // each byte of the seed is changed. abort = 0; for (i = 0; i < 64; i++) { memset(seed, 0, 64); seed[i] = 1; generateDeterministic256(keys[i], seed, 0); for (j = 0; j < i; j++) { if (bigCompare(keys[i], keys[j]) == BIGCMP_EQUAL) { printf("generateDeterministic256() is ignoring byte %d of seed\n", i); abort = 1; break; } } if (abort) { break; } } if (abort) { reportFailure(); } else { reportSuccess(); } // Check that generateDeterministic256() isn't ignoring num. memset(seed, 0, 64); seed[0] = 1; generateDeterministic256(key2, seed, 1); abort = 0; for (j = 0; j < 64; j++) { if (bigCompare(key2, keys[j]) == BIGCMP_EQUAL) { printf("generateDeterministic256() is ignoring num\n"); abort = 1; break; } } if (abort) { reportFailure(); } else { reportSuccess(); } // Check that generateDeterministic256() is actually deterministic. generateDeterministic256(key2, seed, 0); if (bigCompare(key2, keys[0]) != BIGCMP_EQUAL) { printf("generateDeterministic256() is not deterministic\n"); reportFailure(); } else { reportSuccess(); } if (argc != 2) { printf("Usage: %s <n>, where <n> is number of 256 bit samples to take\n", argv[0]); printf("Samples will go into random.dat\n"); exit(1); } sscanf(argv[1], "%d", &num_samples); if (num_samples <= 0) { printf("Invalid number of samples specified\n"); exit(1); } f = fopen("random.dat", "wb"); if (f == NULL) { printf("Could not open random.dat for writing\n"); exit(1); } srand(42); bytes_written = 0; for (i = 0; i < num_samples; i++) { getRandom256(r); bytes_written += fwrite(r, 1, 32, f); } fclose(f); printf("%u bytes written to random.dat\n", bytes_written); finishTests(); exit(0); }
int main(void) { uint8_t temp[128]; uint8_t address1[20]; uint8_t address2[20]; uint8_t name[NAME_LENGTH]; uint8_t encryption_key[WALLET_ENCRYPTION_KEY_LENGTH]; uint8_t new_encryption_key[WALLET_ENCRYPTION_KEY_LENGTH]; uint8_t version[4]; uint8_t *address_buffer; uint8_t one_byte; AddressHandle *handles_buffer; AddressHandle ah; PointAffine public_key; PointAffine *public_key_buffer; int abort; int is_zero; int abort_duplicate; int abort_error; int i; int j; initTests(__FILE__); initWalletTest(); memset(encryption_key, 0, WALLET_ENCRYPTION_KEY_LENGTH); setEncryptionKey(encryption_key); // Blank out non-volatile storage area (set to all nulls). temp[0] = 0; for (i = 0; i < TEST_FILE_SIZE; i++) { fwrite(temp, 1, 1, wallet_test_file); } // sanitiseNonVolatileStorage() should nuke everything. if (sanitiseNonVolatileStorage(0, 0xffffffff) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("Cannot nuke NV storage using sanitiseNonVolatileStorage()\n"); reportFailure(); } // Check that the version field is "wallet not there". if (getWalletInfo(version, temp) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("getWalletInfo() failed after sanitiseNonVolatileStorage() was called\n"); reportFailure(); } if (readU32LittleEndian(version) == VERSION_NOTHING_THERE) { reportSuccess(); } else { printf("sanitiseNonVolatileStorage() does not set version to nothing there\n"); reportFailure(); } // initWallet() hasn't been called yet, so nearly every function should // return WALLET_NOT_THERE somehow. checkFunctionsReturnWalletNotThere(); // The non-volatile storage area was blanked out, so there shouldn't be a // (valid) wallet there. if (initWallet() == WALLET_NOT_THERE) { reportSuccess(); } else { printf("initWallet() doesn't recognise when wallet isn't there\n"); reportFailure(); } // Try creating a wallet and testing initWallet() on it. memcpy(name, "123456789012345678901234567890abcdefghij", NAME_LENGTH); if (newWallet(name) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("Could not create new wallet\n"); reportFailure(); } if (initWallet() == WALLET_NO_ERROR) { reportSuccess(); } else { printf("initWallet() does not recognise new wallet\n"); reportFailure(); } if ((getNumAddresses() == 0) && (walletGetLastError() == WALLET_EMPTY)) { reportSuccess(); } else { printf("New wallet isn't empty\n"); reportFailure(); } // Check that the version field is "unencrypted wallet". if (getWalletInfo(version, temp) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("getWalletInfo() failed after newWallet() was called\n"); reportFailure(); } if (readU32LittleEndian(version) == VERSION_UNENCRYPTED) { reportSuccess(); } else { printf("newWallet() does not set version to unencrypted wallet\n"); reportFailure(); } // Check that sanitise_nv_wallet() deletes wallet. if (sanitiseNonVolatileStorage(0, 0xffffffff) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("Cannot nuke NV storage using sanitiseNonVolatileStorage()\n"); reportFailure(); } if (initWallet() == WALLET_NOT_THERE) { reportSuccess(); } else { printf("sanitiseNonVolatileStorage() isn't deleting wallet\n"); reportFailure(); } // Make some new addresses, then create a new wallet and make sure the // new wallet is empty (i.e. check that newWallet() deletes existing // wallet). newWallet(name); if (makeNewAddress(temp, &public_key) != BAD_ADDRESS_HANDLE) { reportSuccess(); } else { printf("Couldn't create new address in new wallet\n"); reportFailure(); } newWallet(name); if ((getNumAddresses() == 0) && (walletGetLastError() == WALLET_EMPTY)) { reportSuccess(); } else { printf("newWallet() doesn't delete existing wallet\n"); reportFailure(); } // Unload wallet and make sure everything realises that the wallet is // not loaded. if (uninitWallet() == WALLET_NO_ERROR) { reportSuccess(); } else { printf("uninitWallet() failed to do its basic job\n"); reportFailure(); } checkFunctionsReturnWalletNotThere(); // Load wallet again. Since there is actually a wallet there, this // should succeed. if (initWallet() == WALLET_NO_ERROR) { reportSuccess(); } else { printf("uninitWallet() appears to be permanent\n"); reportFailure(); } // Change bytes in non-volatile memory and make sure initWallet() fails // because of the checksum check. if (uninitWallet() != WALLET_NO_ERROR) { printf("uninitWallet() failed to do its basic job 2\n"); reportFailure(); } abort = 0; for (i = 0; i < WALLET_RECORD_LENGTH; i++) { if (nonVolatileRead(&one_byte, (uint32_t)i, 1) != NV_NO_ERROR) { printf("NV read fail\n"); abort = 1; break; } one_byte++; if (nonVolatileWrite(&one_byte, (uint32_t)i, 1) != NV_NO_ERROR) { printf("NV write fail\n"); abort = 1; break; } if (initWallet() == WALLET_NO_ERROR) { printf("Wallet still loads when wallet checksum is wrong, offset = %d\n", i); abort = 1; break; } one_byte--; if (nonVolatileWrite(&one_byte, (uint32_t)i, 1) != NV_NO_ERROR) { printf("NV write fail\n"); abort = 1; break; } } if (!abort) { reportSuccess(); } else { reportFailure(); } // Create 2 new wallets and check that their addresses aren't the same newWallet(name); if (makeNewAddress(address1, &public_key) != BAD_ADDRESS_HANDLE) { reportSuccess(); } else { printf("Couldn't create new address in new wallet\n"); reportFailure(); } newWallet(name); memset(address2, 0, 20); memset(&public_key, 0, sizeof(PointAffine)); if (makeNewAddress(address2, &public_key) != BAD_ADDRESS_HANDLE) { reportSuccess(); } else { printf("Couldn't create new address in new wallet\n"); reportFailure(); } if (memcmp(address1, address2, 20)) { reportSuccess(); } else { printf("New wallets are creating identical addresses\n"); reportFailure(); } // Check that makeNewAddress() wrote to its outputs. is_zero = 1; for (i = 0; i < 20; i++) { if (address2[i] != 0) { is_zero = 0; break; } } if (is_zero) { printf("makeNewAddress() doesn't write the address\n"); reportFailure(); } else { reportSuccess(); } if (bigIsZero(public_key.x)) { printf("makeNewAddress() doesn't write the public key\n"); reportFailure(); } else { reportSuccess(); } // Make some new addresses, up to a limit. // Also check that addresses are unique. newWallet(name); abort = 0; address_buffer = malloc(MAX_TESTING_ADDRESSES * 20); for (i = 0; i < MAX_TESTING_ADDRESSES; i++) { if (makeNewAddress(&(address_buffer[i * 20]), &public_key) == BAD_ADDRESS_HANDLE) { printf("Couldn't create new address in new wallet\n"); abort = 1; break; } for (j = 0; j < i; j++) { if (!memcmp(&(address_buffer[i * 20]), &(address_buffer[j * 20]), 20)) { printf("Wallet addresses aren't unique\n"); abort = 1; break; } } if (abort) { break; } } free(address_buffer); if (!abort) { reportSuccess(); } else { reportFailure(); } // The wallet should be full now. // Check that making a new address now causes an appropriate error. if (makeNewAddress(temp, &public_key) == BAD_ADDRESS_HANDLE) { if (walletGetLastError() == WALLET_FULL) { reportSuccess(); } else { printf("Creating a new address on a full wallet gives incorrect error\n"); reportFailure(); } } else { printf("Creating a new address on a full wallet succeeds (it's not supposed to)\n"); reportFailure(); } // Check that getNumAddresses() fails when the wallet is empty. newWallet(name); if (getNumAddresses() == 0) { if (walletGetLastError() == WALLET_EMPTY) { reportSuccess(); } else { printf("getNumAddresses() doesn't recognise wallet is empty\n"); reportFailure(); } } else { printf("getNumAddresses() succeeds when used on empty wallet\n"); reportFailure(); } // Create a bunch of addresses in the (now empty) wallet and check that // getNumAddresses() returns the right number. address_buffer = malloc(MAX_TESTING_ADDRESSES * 20); public_key_buffer = malloc(MAX_TESTING_ADDRESSES * sizeof(PointAffine)); handles_buffer = malloc(MAX_TESTING_ADDRESSES * sizeof(AddressHandle)); abort = 0; for (i = 0; i < MAX_TESTING_ADDRESSES; i++) { ah = makeNewAddress(&(address_buffer[i * 20]), &(public_key_buffer[i])); handles_buffer[i] = ah; if (ah == BAD_ADDRESS_HANDLE) { printf("Couldn't create new address in new wallet\n"); abort = 1; reportFailure(); break; } } if (!abort) { reportSuccess(); } if (getNumAddresses() == MAX_TESTING_ADDRESSES) { reportSuccess(); } else { printf("getNumAddresses() returns wrong number of addresses\n"); reportFailure(); } // The wallet should contain unique addresses. abort_duplicate = 0; for (i = 0; i < MAX_TESTING_ADDRESSES; i++) { for (j = 0; j < i; j++) { if (!memcmp(&(address_buffer[i * 20]), &(address_buffer[j * 20]), 20)) { printf("Wallet has duplicate addresses\n"); abort_duplicate = 1; reportFailure(); break; } } } if (!abort_duplicate) { reportSuccess(); } // The wallet should contain unique public keys. abort_duplicate = 0; for (i = 0; i < MAX_TESTING_ADDRESSES; i++) { for (j = 0; j < i; j++) { if (bigCompare(public_key_buffer[i].x, public_key_buffer[j].x) == BIGCMP_EQUAL) { printf("Wallet has duplicate public keys\n"); abort_duplicate = 1; reportFailure(); break; } } } if (!abort_duplicate) { reportSuccess(); } // The address handles should start at 1 and be sequential. abort = 0; for (i = 0; i < MAX_TESTING_ADDRESSES; i++) { if (handles_buffer[i] != (AddressHandle)(i + 1)) { printf("Address handle %d should be %d, but got %d\n", i, i + 1, (int)handles_buffer[i]); abort = 1; reportFailure(); break; } } if (!abort) { reportSuccess(); } // While there's a bunch of addresses in the wallet, check that // getAddressAndPublicKey() obtains the same address and public key as // makeNewAddress(). abort_error = 0; abort = 0; for (i = 0; i < MAX_TESTING_ADDRESSES; i++) { ah = handles_buffer[i]; if (getAddressAndPublicKey(address1, &public_key, ah) != WALLET_NO_ERROR) { printf("Couldn't obtain address in wallet\n"); abort_error = 1; reportFailure(); break; } if ((memcmp(address1, &(address_buffer[i * 20]), 20)) || (bigCompare(public_key.x, public_key_buffer[i].x) != BIGCMP_EQUAL) || (bigCompare(public_key.y, public_key_buffer[i].y) != BIGCMP_EQUAL)) { printf("getAddressAndPublicKey() returned mismatching address or public key, ah = %d\n", i); abort = 1; reportFailure(); break; } } if (!abort) { reportSuccess(); } if (!abort_error) { reportSuccess(); } // Test getAddressAndPublicKey() and getPrivateKey() functions using // invalid and then valid address handles. if (getAddressAndPublicKey(temp, &public_key, 0) == WALLET_INVALID_HANDLE) { reportSuccess(); } else { printf("getAddressAndPublicKey() doesn't recognise 0 as invalid address handle\n"); reportFailure(); } if (getPrivateKey(temp, 0) == WALLET_INVALID_HANDLE) { reportSuccess(); } else { printf("getPrivateKey() doesn't recognise 0 as invalid address handle\n"); reportFailure(); } if (getAddressAndPublicKey(temp, &public_key, BAD_ADDRESS_HANDLE) == WALLET_INVALID_HANDLE) { reportSuccess(); } else { printf("getAddressAndPublicKey() doesn't recognise BAD_ADDRESS_HANDLE as invalid address handle\n"); reportFailure(); } if (getPrivateKey(temp, BAD_ADDRESS_HANDLE) == WALLET_INVALID_HANDLE) { reportSuccess(); } else { printf("getPrivateKey() doesn't recognise BAD_ADDRESS_HANDLE as invalid address handle\n"); reportFailure(); } if (getAddressAndPublicKey(temp, &public_key, handles_buffer[0]) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("getAddressAndPublicKey() doesn't recognise valid address handle\n"); reportFailure(); } if (getPrivateKey(temp, handles_buffer[0]) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("getPrivateKey() doesn't recognise valid address handle\n"); reportFailure(); } free(address_buffer); free(public_key_buffer); free(handles_buffer); // Check that changeEncryptionKey() works. memset(new_encryption_key, 0, WALLET_ENCRYPTION_KEY_LENGTH); new_encryption_key[0] = 1; if (changeEncryptionKey(new_encryption_key) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("Couldn't change encryption key\n"); reportFailure(); } // Check that the version field is "encrypted wallet". if (getWalletInfo(version, temp) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("getWalletInfo() failed after changeEncryptionKey() was called\n"); reportFailure(); } if (readU32LittleEndian(version) == VERSION_IS_ENCRYPTED) { reportSuccess(); } else { printf("changeEncryptionKey() does not set version to encrypted wallet\n"); reportFailure(); } // Check name matches what was given in newWallet(). if (!memcmp(temp, name, NAME_LENGTH)) { reportSuccess(); } else { printf("getWalletInfo() doesn't return correct name when wallet is loaded\n"); reportFailure(); } // Check that getWalletInfo() still works after unloading wallet. uninitWallet(); if (getWalletInfo(version, temp) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("getWalletInfo() failed after uninitWallet() was called\n"); reportFailure(); } if (readU32LittleEndian(version) == VERSION_IS_ENCRYPTED) { reportSuccess(); } else { printf("uninitWallet() caused wallet version to change\n"); reportFailure(); } // Check name matches what was given in newWallet(). if (!memcmp(temp, name, NAME_LENGTH)) { reportSuccess(); } else { printf("getWalletInfo() doesn't return correct name when wallet is not loaded\n"); reportFailure(); } // Change wallet's name and check that getWalletInfo() reflects the // name change. initWallet(); memcpy(name, "HHHHH HHHHHHHHHHHHHHHHH HHHHHHHHHHHHHH ", NAME_LENGTH); if (changeWalletName(name) == WALLET_NO_ERROR) { reportSuccess(); } else { printf("changeWalletName() couldn't change name\n"); reportFailure(); } getWalletInfo(version, temp); if (!memcmp(temp, name, NAME_LENGTH)) { reportSuccess(); } else { printf("getWalletInfo() doesn't reflect name change\n"); reportFailure(); } // Check that name change is preserved when unloading and loading a // wallet. uninitWallet(); getWalletInfo(version, temp); if (!memcmp(temp, name, NAME_LENGTH)) { reportSuccess(); } else { printf("getWalletInfo() doesn't reflect name change after unloading wallet\n"); reportFailure(); } // Check that initWallet() succeeds (changing the name changes the // checksum, so this tests whether the checksum was updated). if (initWallet() == WALLET_NO_ERROR) { reportSuccess(); } else { printf("initWallet() failed after name change\n"); reportFailure(); } getWalletInfo(version, temp); if (!memcmp(temp, name, NAME_LENGTH)) { reportSuccess(); } else { printf("getWalletInfo() doesn't reflect name change after reloading wallet\n"); reportFailure(); } // Check that loading the wallet with the old key fails. uninitWallet(); setEncryptionKey(encryption_key); if (initWallet() == WALLET_NOT_THERE) { reportSuccess(); } else { printf("Loading wallet with old encryption key succeeds\n"); reportFailure(); } // Check that loading the wallet with the new key succeeds. uninitWallet(); setEncryptionKey(new_encryption_key); if (initWallet() == WALLET_NO_ERROR) { reportSuccess(); } else { printf("Loading wallet with new encryption key fails\n"); reportFailure(); } // Test the getAddressAndPublicKey() and getPrivateKey() functions on an // empty wallet. newWallet(name); if (getAddressAndPublicKey(temp, &public_key, 0) == WALLET_EMPTY) { reportSuccess(); } else { printf("getAddressAndPublicKey() doesn't deal with empty wallets correctly\n"); reportFailure(); } if (getPrivateKey(temp, 0) == WALLET_EMPTY) { reportSuccess(); } else { printf("getPrivateKey() doesn't deal with empty wallets correctly\n"); reportFailure(); } fclose(wallet_test_file); finishTests(); exit(0); }