const account_object& database_fixture::account_create( const string& name, const public_key_type& key ) { return account_create( name, key, key ); }
int account_createFromString(struct Account *a, char *buffer) { // Necessary buffers char nrBuffer[MAX_BUFFER_LEN]; char userBuffer[17]; char pinBuffer[MAX_BUFFER_LEN]; char balanceBuffer[MAX_BUFFER_LEN]; double balance; unsigned int number; // Get the account number strncpy(nrBuffer, buffer, 7); nrBuffer[7] = '\0'; buffer = buffer + 8; // Shift right number = atoi(nrBuffer); // Get the user name strncpy(userBuffer, buffer, 20); userBuffer[20] = '\0'; buffer = buffer + 21; // Shift right // Get the pin strncpy(pinBuffer, buffer, 4); pinBuffer[4] = '\0'; buffer = buffer + 5; // Shift right // Get the balance strcpy(balanceBuffer, buffer); balance = atof(balanceBuffer); account_create(a, number, userBuffer, pinBuffer, balance); return 1; }
struct Account* server_getAccountbyID(struct Server *s, accountnr_t nr) { struct Account *a; struct Account key; account_create(&key, nr, "KEY", "keyy", 0); a = (struct Account*) bsearch(&key, s->accounts, s->totalAccounts, sizeof(struct Account), account_compare); return a; }
int server_createAccount(struct Server *s, accountnr_t nr, char *usr, char *pin, double initialBalance) { if (server_accountAlreadyExists(s, nr)) return 0; struct Account *a = malloc(sizeof(struct Account)); int status = account_create(a, nr, usr, pin, initialBalance); // Dynamic memory allocation server_addAccountRealloc(s, a); return status; }
END_TEST START_TEST (test_account_free) { Account * a = account_create(); /*!< @todo Mock account create or hand code? */ account_free(a); fail_unless(a == NULL, "Memory not properly freed"); }
static t_account * account_load(t_attrgroup *attrgroup) { t_account * account; assert(attrgroup); if (!(account = account_create(NULL,NULL))) { eventlog(eventlog_level_error,__FUNCTION__,"could not create account"); return NULL; } account->attrgroup = attrgroup; return account; }
END_TEST START_TEST (test_account_create_failure) { #if 0 /** * @todo Add tests like the following as conditions are reported as not * being handled correctly. */ errno = 0; if (account_create() == NULL) { fail_unless(errno == ENOMEM, "Couldn't allocate memory"); } #endif }
int main() //@ requires true; //@ ensures true; { struct account *myAccount = account_create(-100); account_deposit(myAccount, 200); int w1 = account_withdraw(myAccount, 50); //assert(w1 == 50); int b1 = account_get_balance(myAccount); //assert(b1 == 150); int w2 = account_withdraw(myAccount, 300); //assert(w2 == 250); int b2 = account_get_balance(myAccount); //assert(b2 == -100); account_dispose(myAccount); return 0; }
const account_object &database_fixture::account_create( const string &name, const public_key_type &key, const public_key_type &post_key ) { try { return account_create( name, STEEMIT_INIT_MINER_NAME, init_account_priv_key, 100, key, post_key, ""); } FC_CAPTURE_AND_RETHROW((name)); }
const account_object& database_fixture::account_create( const string& name, const public_key_type& key, const public_key_type& post_key ) { try { return account_create( name, STEEMIT_INIT_MINER_NAME, init_account_priv_key, std::max( db.get_witness_schedule_object().median_props.account_creation_fee.amount * STEEMIT_CREATE_ACCOUNT_WITH_STEEM_MODIFIER, share_type( 100 ) ), key, post_key, "" ); } FC_CAPTURE_AND_RETHROW( (name) ); }
END_TEST START_TEST (test_get_account_property) { Account * a = account_create(); /** * @todo Mock things … */ fail_unless(_get_account_property(a, CONTAINER_COUNT, FALSE) == 3, "Incorrect container account returned!"); fail_unless(_get_account_property(a, CONTAINER_COUNT, TRUE) == 3, "Incorrect container account returned!"); /** * @todo Check accesses to request function. */ account_free(a); }
int admin_createAccount() { // Variables char buffer[MAX_BUFFER_LEN]; char user[MAX_USER_LEN + 1]; char pin[MAX_PIN_LEN + 1]; double balance; accountnr_t number; // Ask input cls(); printf("Criar conta\n" "----------------\n"); // Number: do { printf("Numero: "); gets(buffer); number = atoi(buffer); } while (strlen(buffer) > 7 || strlen(buffer) == 0 || number < 1 || number > 9999999 || !isInteger(buffer)); // User do { printf("Utilizador: "); gets(buffer); } while (strlen(buffer) > 20 || strlen(buffer) < 3); strncpy(user, buffer, 20); user[20] = '\0'; // PIN do { printf("PIN(size=4): "); gets(buffer); } while (strlen(buffer) != 4 || (strchr(buffer, ' ')) != NULL); //NO SPACES IN PIN strncpy(pin, buffer, 4); pin[4] = '\0'; // Initial balance do { printf("Balance: "); gets(buffer); balance = atof(buffer); } while (balance < 0 || !isFloat(buffer)); struct Account a; if (!account_create(&a, number, user, pin, balance)) { printf("Dados da conta invalidos!\n"); return 1; } else { printf("echo: %s\n", account_toString(&a)); struct Request r; char *msg = malloc(sizeof(char) * 10); char* wrStr = malloc(sizeof(char) * 128); sprintf(wrStr, "CREATE ACCOUNT %i %s|%s %f\n", number, user, pin, balance); request_create(&r, getpid(), "ADMIN", wrStr); request_writeFIFO("/tmp/requests", &r, NULL); request_waitFIFO(fifoname, NULL, msg); printf("%s\n", msg); getchar(); if (strcmp(msg, "OK") == 0) return 1; else return 0; } }
int account_createAutoIncrement(struct Account *a, char *usr, char *pin, double initialBalance) { return account_create(a, ++lastAccountNumber, usr, pin, initialBalance); }