/* performs properties change with support of undoing */ static void file_attrib(char *path, DWORD add, DWORD sub, int recurse_dirs) { /* FIXME: set attributes recursively. */ DWORD attrs = GetFileAttributes(path); if(attrs == INVALID_FILE_ATTRIBUTES) { LOG_WERROR(GetLastError()); return; } if(add != 0) { const size_t wadd = add; if(perform_operation(OP_ADDATTR, NULL, (void *)wadd, path, NULL) == 0) { add_operation(OP_ADDATTR, (void *)wadd, (void *)(~attrs & wadd), path, ""); } } if(sub != 0) { const size_t wsub = sub; if(perform_operation(OP_SUBATTR, NULL, (void *)wsub, path, NULL) == 0) { add_operation(OP_SUBATTR, (void *)wsub, (void *)(~attrs & wsub), path, ""); } } }
static void test_to_many_commands_and_continue(void) { static int undo_levels = 3; init_undo_list(&exec_skip, &undo_levels); cmd_group_begin("msg0"); cmd_group_end(); cmd_group_continue(); free(replace_group_msg("HI")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg0", "undo_msg0")); cmd_group_end(); cmd_group_continue(); free(replace_group_msg("HI")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg0", "undo_msg0")); cmd_group_end(); cmd_group_continue(); free(replace_group_msg("HI")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg0", "undo_msg0")); cmd_group_end(); cmd_group_continue(); free(replace_group_msg("HI")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg0", "undo_msg0")); cmd_group_end(); cmd_group_continue(); free(replace_group_msg("HI")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg0", "undo_msg0")); cmd_group_end(); }
static void setup(void) { static int undo_levels = 10; int ret_code; init_undo_list_for_tests(&exec_func, &undo_levels); cmd_group_begin("msg1"); ret_code = add_operation(OP_MOVE, NULL, NULL, "do_msg1", "undo_msg1"); assert(ret_code == 0); cmd_group_end(); cmd_group_begin("msg2"); ret_code = add_operation(OP_MOVE, NULL, NULL, "do_msg2_cmd1", "undo_msg2_cmd1"); assert(ret_code == 0); ret_code = add_operation(OP_MOVE, NULL, NULL, "do_msg2_cmd2", "undo_msg2_cmd2"); assert(ret_code == 0); cmd_group_end(); cmd_group_begin("msg3"); ret_code = add_operation(OP_MOVE, NULL, NULL, "do_msg3", "undo_msg3"); assert(ret_code == 0); cmd_group_end(); }
static void test_disbalance(void) { static int undo_levels = 10; init_undo_list(&execute_fail, &undo_levels); reset_undo_list(); cmd_group_begin("msg0"); assert_int_equal(0, add_operation(OP_COPY, NULL, NULL, "do_msg0", "undo_msg0")); cmd_group_end(); cmd_group_begin("msg1"); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg1", "undo_msg1")); cmd_group_end(); assert_int_equal(0, undo_group()); assert_int_equal(-3, undo_group()); assert_int_equal(-1, undo_group()); assert_int_equal(-4, redo_group()); assert_int_equal(0, redo_group()); assert_int_equal(-1, redo_group()); }
void convert_currency_account(const QString& currency, bool bfirst) { double d_bank; QString s_cahs_bank; if(!get_data_from_bank(d_bank, s_cahs_bank)) { return; } if(currency == s_cahs_bank) { return; } set_data_to_bank(d_bank, currency); if(bfirst) { return;//if this first load program, do not register this operation in database } Db_dat data_o; data_o.date = QDateTime::currentDateTime().toString(get_display_format()); data_o.currency = currency; data_o.count_d = d_bank; QString s = QString("%1 %2 %3 %4").arg(QObject::tr("Change currency bank from")) .arg(s_cahs_bank).arg(QObject::tr("to")).arg(currency); data_o.descr = s; add_operation(d_bank, data_o,true); }
static void file_chmod(char *path, const char *mode, const char *inv_mode, int recurse_dirs) { int op = recurse_dirs ? OP_CHMODR : OP_CHMOD; if(perform_operation(op, (void *)mode, path, NULL) == 0) add_operation(op, strdup(mode), strdup(inv_mode), path, ""); }
static void test_cannot_be_undone(void) { cmd_group_begin("msg0"); assert_int_equal(0, add_operation(OP_REMOVE, NULL, NULL, "do_msg0", "")); cmd_group_end(); assert_int_equal(-5, undo_group()); }
static void test_removing_of_incomplete_groups(void) { static int undo_levels = 10; int i; init_undo_list(&exec_dummy, &undo_levels); cmd_group_begin("msg0"); for(i = 0; i < 10; i++) assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg0", "undo_msg0")); cmd_group_end(); cmd_group_begin("msg1"); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg1", "undo_msg1")); cmd_group_end(); assert_int_equal(0, undo_group()); assert_int_equal(-1, undo_group()); }
static void test_negative_undolevel(void) { static int undo_levels = -1; init_undo_list_for_tests(&execute_dummy, &undo_levels); cmd_group_begin("msg4"); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg4", "undo_msg4")); cmd_group_end(); assert_int_equal(-1, undo_group()); }
static void test_skipping(void) { static int undo_levels = 10; init_undo_list(&exec_skip, &undo_levels); cmd_group_begin("msg0"); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg0", "undo_msg0")); cmd_group_end(); assert_int_equal(-6, undo_group()); assert_int_equal(-4, redo_group()); }
static void test_cmd_1undo_1redo(void) { static int undo_levels = 10; reset_undo_list(); init_undo_list(&exec_dummy, &undo_levels); cmd_group_begin("msg0"); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg0", "undo_msg0")); cmd_group_end(); assert_int_equal(0, undo_group()); assert_int_equal(0, redo_group()); }
static void test_list_truncating(void) { assert_int_equal(0, undo_group()); assert_int_equal(0, undo_group()); assert_int_equal(0, undo_group()); assert_int_equal(0, redo_group()); assert_int_equal(0, redo_group()); assert_int_equal(0, redo_group()); assert_int_equal(0, undo_group()); assert_int_equal(0, undo_group()); cmd_group_begin("msg4"); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg4", "undo_msg4")); cmd_group_end(); assert_int_equal(-1, redo_group()); assert_int_equal(11, i); }
static void test_too_many_commands(void) { cmd_group_begin("msg4"); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg40", "undo_msg40")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg41", "undo_msg41")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg42", "undo_msg42")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg43", "undo_msg43")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg44", "undo_msg44")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg45", "undo_msg45")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg46", "undo_msg46")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg47", "undo_msg47")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg48", "undo_msg48")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg49", "undo_msg49")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg4a", "undo_msg4a")); assert_int_equal(0, add_operation(OP_MOVE, NULL, NULL, "do_msg4b", "undo_msg4b")); cmd_group_end(); }
void set_data_creditor(Db_dat data) { QSqlQuery query(QSqlDatabase::database(data_u.NameDB)); double idata = 0; QString s_cash, s_cash_credit; get_data_from_bank(idata, s_cash); query.prepare("select * from creditors where 1"); query.exec(); bool b=false;//find record id finded - change, else create new while (query.next()) { QSqlQuery query_in(QSqlDatabase::database(data_u.NameDB)); if(data.date == query.value(0).toString()) { s_cash_credit = query.value(3).toString(); double n = query.value(2).toDouble()-data.count_d; if (n > 0) { query_in.prepare("update creditors set count=:count where (date_c=:date_c)"); query_in.bindValue(":count", n); query_in.bindValue(":date_c", data.date); } else { query_in.prepare("delete from creditors where (date_c=:date_c)"); query_in.bindValue(":date_c", data.date); } if (!query_in.exec()) { qDebug() << query_in.lastError(); return; } b = true; break; } } if (!b) { //create new credit idata -= data.count_d;//check many in count if(idata<0) { QMessageBox::information(0,QObject::tr("Erorr operation"),QObject::tr("No cash")); return; } query.prepare("INSERT INTO creditors (date_c, name_c, count," "currency_name, percent, type, description, date_incr) " "VALUES (:date_c, :name, :count, :currency_name, :percent," ":type, :description, :date_incr)"); query.bindValue(":count", data.count_d); query.bindValue(":currency_name", s_cash); query.bindValue(":percent", data.percent); query.bindValue(":type", data.type); query.bindValue(":date_c", data.date); query.bindValue(":name", data.Name); query.bindValue(":description", data.descr); query.bindValue(":date_incr", data.date_incr); if (!query.exec()) { qDebug() << query.lastError(); return; } } Db_dat data_o; QString s_h = "<b>%1</b> <b>%2:</b>"; bool bconverted = false; double d_c_cash= data.count_d; if(b) { if(s_cash == s_cash_credit) { //convert cash if currency bank idata += data.count_d; // not equable with currency credit } else { d_c_cash = convert_currency(data.count_d,s_cash_credit,s_cash); idata += d_c_cash; bconverted = true; } data_o.descr = s_h.arg(QObject::tr("Credit amortiazation")).arg(QObject::tr("debtor"))+data.Name; if (bconverted) { data_o.descr+="<br><b><font color=\"red\">"+QObject::tr("Cash automatically converted: from") +" "+QString::number(data.count_d)+" "+s_cash_credit +" "+QObject::tr("to")+" " +QString::number(d_c_cash)+""+s_cash+"</font></b>"; } else { data_o.descr = data.descr; } } data_o.date = data.date; data_o.currency = s_cash; data_o.count_d = d_c_cash; add_operation(b, data_o); set_data_to_bank(idata, s_cash); }
AST_Decl *UTL_Scope::call_add() { AST_Decl *result = NULL; AST_Decl *decl; UTL_ScopeActiveIterator *i; UTL_Scope *scope; i = new UTL_ScopeActiveIterator(this, UTL_Scope::IK_decls); while (!(i->is_done())) { decl = i->item(); scope = 0; switch (decl->node_type()) { case AST_Decl::NT_argument: result = add_argument(AST_Argument::narrow_from_decl(decl)); break; case AST_Decl::NT_array: result = add_array(AST_Array::narrow_from_decl(decl)); break; case AST_Decl::NT_attr: result = add_attribute(AST_Attribute::narrow_from_decl(decl)); break; case AST_Decl::NT_const: result = add_constant(AST_Constant::narrow_from_decl(decl)); break; case AST_Decl::NT_enum: scope = AST_Enum::narrow_from_decl(decl); result = add_enum(AST_Enum::narrow_from_decl(decl)); break; case AST_Decl::NT_enum_val: result = add_enum_val(AST_EnumVal::narrow_from_decl(decl)); break; case AST_Decl::NT_except: scope = AST_Exception::narrow_from_decl(decl); result = add_exception(AST_Exception::narrow_from_decl(decl)); break; case AST_Decl::NT_field: result = add_field(AST_Field::narrow_from_decl(decl)); break; case AST_Decl::NT_interface: scope = AST_Interface::narrow_from_decl(decl); result = add_interface(AST_Interface::narrow_from_decl(decl)); break; case AST_Decl::NT_interface_fwd: result = add_interface_fwd(AST_InterfaceFwd::narrow_from_decl(decl)); break; case AST_Decl::NT_module: scope = AST_Module::narrow_from_decl(decl); result = add_module(AST_Module::narrow_from_decl(decl)); break; case AST_Decl::NT_op: result = add_operation(AST_Operation::narrow_from_decl(decl)); scope = AST_Operation::narrow_from_decl(decl); break; case AST_Decl::NT_pre_defined: result = add_predefined_type(AST_PredefinedType::narrow_from_decl(decl)); break; case AST_Decl::NT_sequence: result = add_sequence(AST_Sequence::narrow_from_decl(decl)); break; case AST_Decl::NT_string: result = add_string(AST_String::narrow_from_decl(decl)); break; case AST_Decl::NT_struct: result = add_structure(AST_Structure::narrow_from_decl(decl)); scope = AST_Structure::narrow_from_decl(decl); break; case AST_Decl::NT_typedef: result = add_typedef(AST_Typedef::narrow_from_decl(decl)); break; case AST_Decl::NT_union: result = add_union(AST_Union::narrow_from_decl(decl)); scope = AST_Union::narrow_from_decl(decl); break; case AST_Decl::NT_union_branch: result = add_union_branch(AST_UnionBranch::narrow_from_decl(decl)); break; // case AST_Decl::NT_opaque: // result = add_opaque(AST_Opaque::narrow_from_decl(decl)); // break; case AST_Decl::NT_value: result = add_valuetype (AST_Value::narrow_from_decl (decl)); scope = AST_Value::narrow_from_decl (decl); break; case AST_Decl::NT_value_fwd: result = add_valuetype_fwd(AST_ValueFwd::narrow_from_decl(decl)); break; case AST_Decl::NT_state_member: result = add_state_member(AST_StateMember::narrow_from_decl(decl)); break; default: return NULL; } if (scope) scope->call_add(); i->next(); } delete i; return result; }