bool test_app_arguments_validate_ordinal_required_discontinuity (Test *test) { char *argv[] = { "./app", "--argument" }; int value_1; int value_2; AppArgument arguments[] = { ARGUMENT_ORDINAL_INTEGER (1, false, &value_1, "test"), ARGUMENT_ORDINAL_INTEGER (1, true, &value_2, "test"), ARGUMENT_END }; TITLE (); CATCH (app_arguments (2, argv, arguments)) CATCH (error_count () < 2); CATCH (error_at (1).error != ErrorAppArgumentOrdinalRequiredDiscontinuity); PASS (); }
CONFUGA_API int confuga_lookup (confuga *C, const char *path, confuga_fid_t *fid, confuga_off_t *size) { int rc; enum CONFUGA_FILE_TYPE type; RESOLVE(path) debug(D_CONFUGA, "lookup(`%s')", unresolved_path); CATCH(lookup(C, path, fid, size, &type)); PROLOGUE }
int MailboxState_getAcl(T M, uint64_t userid, struct ACLMap *map) { int i; volatile int t = DM_SUCCESS; gboolean gotrow = FALSE; uint64_t anyone; Connection_T c; ResultSet_T r; PreparedStatement_T s; g_return_val_if_fail(MailboxState_getId(M),DM_EGENERAL); if (! (auth_user_exists(DBMAIL_ACL_ANYONE_USER, &anyone))) return DM_EQUERY; c = db_con_get(); TRY s = db_stmt_prepare(c, "SELECT lookup_flag,read_flag,seen_flag," "write_flag,insert_flag,post_flag," "create_flag,delete_flag,deleted_flag,expunge_flag,administer_flag " "FROM %sacl " "WHERE mailbox_id = ? AND user_id = ?",DBPFX); db_stmt_set_u64(s, 1, MailboxState_getId(M)); db_stmt_set_u64(s, 2, userid); r = db_stmt_query(s); if (! db_result_next(r)) { /* else check the 'anyone' user */ db_stmt_set_u64(s, 2, anyone); r = db_stmt_query(s); if (db_result_next(r)) gotrow = TRUE; } else { gotrow = TRUE; } if (gotrow) { i = 0; map->lookup_flag = db_result_get_bool(r,i++); map->read_flag = db_result_get_bool(r,i++); map->seen_flag = db_result_get_bool(r,i++); map->write_flag = db_result_get_bool(r,i++); map->insert_flag = db_result_get_bool(r,i++); map->post_flag = db_result_get_bool(r,i++); map->create_flag = db_result_get_bool(r,i++); map->delete_flag = db_result_get_bool(r,i++); map->deleted_flag = db_result_get_bool(r,i++); map->expunge_flag = db_result_get_bool(r,i++); map->administer_flag = db_result_get_bool(r,i++); } CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
bool test_file_path_size_1 (Test *test) { char *path; TITLE (); file_path_size (0); CATCH (!(path = directory_current_path ())); memory_destroy (path); PASS (); }
bool test_pattern_search_create (Test *test) { PatternSearch *search; const char *memory = "a"; TITLE (); CATCH (!(search = pattern_search_create ((const unsigned char *)memory, string_length (memory) + 1, "a", true))); pattern_search_destroy (search); PASS (); }
bool test_ascii_is_white_space (Test *test) { int i; TITLE (); for (i = SCHAR_MIN; i <= SCHAR_MAX; i++) { if ((char)i == ' ' || (char)i == '\f' || (char)i == '\n' || (char)i == '\r' || (char)i == '\t' || (char)i == '\v') { CATCH (!ascii_is_white_space ((char)i)); } else { CATCH (ascii_is_white_space ((char)i)); } } PASS (); }
bool test_file_close (Test *test) { Directory *directory; File *file; char *path; TITLE (); CATCH (!(path = directory_current_path ())); CATCH (!string_append (&path, "/stage/open")); /* d stage/open f f1 */ CATCH (!(directory = directory_open (path))); string_destroy (path); CATCH (!directory_read (directory)); CATCH (!(file = directory_find_file (directory, "f1"))); file_close (file); directory_close (directory); PASS (); }
bool test_big_int_add_function_call_1 (Test *test) { BigInt *a, *b, *to; int i; TITLE (); CATCH (!(a = big_int_create (0))); CATCH (!(b = big_int_create (0))); CATCH (!(to = big_int_create (0))); a->memory[0] = 5U; b->memory[0] = 5U; for (i = 1; i < 32; i++) { a->memory[i] = 0U; b->memory[i] = 0U; } a->digits = 32; b->digits = 32; memory_commit_limit (memory_commit_size ()); CATCH (big_int_add (a, b, to)); CATCH (error_at (0).error != ErrorFunctionCall); CATCH (error_at (0).code != 1); big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
bool test_file_readline_f2 (Test *test) { Directory *directory; File *file; char *path; char *line; size_t bytes_read; TITLE (); CATCH (!(path = directory_current_path ())); CATCH (!string_append (&path, "/stage/readline")); /* d stage/readline f f2 f f3 \ \ 0 \ AB \ 012 \ ABCD \ 01234 \ ABCD \ 012 \ AB \ 0 f f1 */ CATCH (!(directory = directory_open (path))); string_destroy (path); CATCH (!directory_read (directory)); CATCH (!(file = directory_find_file (directory, "f2"))); CATCH (!file_open (file)); CATCH (!(line = string_create_with_size (1))); CATCH (!file_readline (file, line, &bytes_read)); CATCH (bytes_read != 0); CATCH (memory_size (line) != 1); directory_close (directory); string_destroy (line); PASS (); }
bool test_unsigned_long_long_private_max (Test *test) { unsigned int a, b, max; unsigned long long computed; TITLE (); for (max = 1; max < 9; max++) { a = 0; b = 0; unsigned_long_long_private_max (max - 1); do { if (a > max - 1 || b > max - 1 || a + b > max - 1) { CATCH (unsigned_long_long_add (a, b, &computed)); } else { CATCH (!unsigned_long_long_add (a, b, &computed)); CATCH (computed != a + b); } if (a > max - 1 || b > max - 1 || a * b > max - 1) { CATCH (unsigned_long_long_mul (a, b, &computed)); } else { CATCH (!unsigned_long_long_mul (a, b, &computed)); CATCH (computed != a * b); } } while (combinations_a_b (&a, &b, max, max)); } PASS (); }
int ccnet_db_statement_set_int (CcnetDBStatement *p, int idx, int x) { TRY PreparedStatement_setInt (p->p, idx, x); RETURN (0); CATCH (SQLException) g_warning ("Error set int in prep stmt: %s.\n", Exception_frame.message); return -1; END_TRY; return -1; }
bool test_ascii_is_digit_octal (Test *test) { int i; TITLE (); for (i = SCHAR_MIN; i <= SCHAR_MAX; i++) { if ((char)i == '0' || (char)i == '1' || (char)i == '2' || (char)i == '3' || (char)i == '4' || (char)i == '5' || (char)i == '6' || (char)i == '7') { CATCH (!ascii_is_digit_octal ((char)i)); } else { CATCH (ascii_is_digit_octal ((char)i)); } } PASS (); }
char* python_save_file(char **dest, const char *filename) { char *ret; PyObject *module, *mainthing, *pyret; printf("the module being used for file is %s\n", config_get("module_file")); module = PyDict_GetItemString(modulemap, config_get("module_file")); CATCH(module, bottom_save_file); mainthing = PyObject_CallMethod(module, "init", NULL); CATCH(mainthing, bottom_save_file); pyret = PyObject_CallMethod(mainthing, "save_file", "s", filename); CATCH(pyret, bottom_save_file); ret = PyUnicode_AsUTF8(pyret); CATCH(ret, bottom_save_file); bottom_save_file: // label if (PyErr_Occurred()) { PyErr_Print(); } *dest = strdup(ret); Py_DecRef(mainthing); Py_DecRef(pyret); return *dest; }
CONFUGA_API int confuga_opendir(confuga *C, const char *path, confuga_dir **D) { int rc; RESOLVE(path); debug(D_CONFUGA, "opendir(`%s')", unresolved_path); *D = malloc(sizeof(confuga_dir)); if (*D == NULL) CATCH(ENOMEM); DIR *dir = opendir(path); if(dir) { (*D)->C = C; (*D)->dir = dir; strcpy((*D)->path, unresolved_path); return 0; } else { CATCH(errno); } out: debug(D_CONFUGA, "= %d (%s)", rc, strerror(rc)); if (rc) free(*D); return rc; }
int dm_sievescript_rename(uint64_t user_idnr, char *scriptname, char *newname) { int active = 0; Connection_T c; ResultSet_T r; PreparedStatement_T s; volatile int t = FALSE; assert(scriptname); /* * According to the draft RFC, a script with the same * name as an existing script should *atomically* replace it. */ c = db_con_get(); TRY db_begin_transaction(c); s = db_stmt_prepare(c,"SELECT active FROM %ssievescripts WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_u64(s,1, user_idnr); db_stmt_set_str(s,2, newname); r = db_stmt_query(s); if (db_result_next(r)) { active = db_result_get_int(r,0); db_con_clear(c); s = db_stmt_prepare(c, "DELETE FROM %ssievescripts WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_u64(s, 1, user_idnr); db_stmt_set_str(s, 2, newname); db_stmt_exec(s); } db_con_clear(c); s = db_stmt_prepare(c, "UPDATE %ssievescripts SET name = ?, active = ? WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_str(s, 1, newname); db_stmt_set_int(s, 2, active); db_stmt_set_u64(s, 3, user_idnr); db_stmt_set_str(s, 4, scriptname); db_stmt_exec(s); t = db_commit_transaction(c); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; db_rollback_transaction(c); FINALLY db_con_close(c); END_TRY; return t; }
gboolean seaf_db_check_for_existence (SeafDB *db, const char *sql, gboolean *db_err) { Connection_T conn; ResultSet_T result; gboolean ret = TRUE; *db_err = FALSE; conn = get_db_connection (db); if (!conn) { *db_err = TRUE; return FALSE; } TRY result = Connection_executeQuery (conn, "%s", sql); CATCH (SQLException) g_warning ("Error exec query %s: %s.\n", sql, Exception_frame.message); Connection_close (conn); *db_err = TRUE; return FALSE; END_TRY; TRY if (!ResultSet_next (result)) ret = FALSE; CATCH (SQLException) g_warning ("Error exec query %s: %s.\n", sql, Exception_frame.message); Connection_close (conn); *db_err = TRUE; return FALSE; END_TRY; Connection_close (conn); return ret; }
bool test_unsigned_long_long_bit_most_significant (Test *test) { TITLE (); CATCH (unsigned_long_long_bit_most_significant (0) != 0); CATCH (unsigned_long_long_bit_most_significant (1) != 0); CATCH (unsigned_long_long_bit_most_significant (2) != 1); CATCH (unsigned_long_long_bit_most_significant (3) != 1); CATCH (unsigned_long_long_bit_most_significant (4) != 2); CATCH (unsigned_long_long_bit_most_significant ((unsigned char)-1) != 7); CATCH (unsigned_long_long_bit_most_significant ((unsigned long long)-1) != 63); PASS (); }
bool test_big_int_add_4 (Test *test) { BigInt *a, *b, *to; TITLE (); CATCH (!(a = big_int_create (999))); CATCH (!(b = big_int_create (11))); CATCH (!(to = big_int_create (0))); CATCH (!big_int_add (a, b, to)); CATCH (to->digits != 4); CATCH (to->memory[0] != 1U); CATCH (to->memory[1] != 0U); CATCH (to->memory[2] != 1U); CATCH (to->memory[3] != 0U); big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
int ccnet_db_statement_set_string (CcnetDBStatement *p, int idx, const char *s) { TRY PreparedStatement_setString (p->p, idx, s); RETURN (0); CATCH (SQLException) g_warning ("Error set string in prep stmt: %s.\n", Exception_frame.message); return -1; END_TRY; return -1; }
unsigned MailboxState_getPermission(T M) { if (! M->permission) { Connection_T c = db_con_get(); TRY db_getmailbox_permission(M, c); CATCH(SQLException) LOG_SQLERROR; FINALLY db_con_close(c); END_TRY; } return M->permission; }
int seaf_db_rollback (SeafDBTrans *trans) { Connection_T conn = trans->conn; TRY Connection_rollback (conn); CATCH (SQLException) g_warning ("Rollback failed: %s.\n", Exception_frame.message); return -1; END_TRY; return 0; }
int seaf_db_foreach_selected_row (SeafDB *db, const char *sql, SeafDBRowFunc callback, void *data) { Connection_T conn; ResultSet_T result; SeafDBRow seaf_row; int n_rows = 0; conn = get_db_connection (db); if (!conn) return -1; TRY result = Connection_executeQuery (conn, "%s", sql); CATCH (SQLException) g_warning ("Error exec query %s: %s.\n", sql, Exception_frame.message); Connection_close (conn); return -1; END_TRY; seaf_row.res = result; TRY while (ResultSet_next (result)) { n_rows++; if (!callback (&seaf_row, data)) break; } CATCH (SQLException) g_warning ("Error exec query %s: %s.\n", sql, Exception_frame.message); Connection_close (conn); return -1; END_TRY; Connection_close (conn); return n_rows; }
char * seaf_db_get_string (SeafDB *db, const char *sql) { char *ret = NULL; const char *s; Connection_T conn; ResultSet_T result; SeafDBRow seaf_row; conn = get_db_connection (db); if (!conn) return NULL; TRY result = Connection_executeQuery (conn, "%s", sql); CATCH (SQLException) g_warning ("Error exec query %s: %s.\n", sql, Exception_frame.message); Connection_close (conn); return NULL; END_TRY; seaf_row.res = result; TRY if (ResultSet_next (result)) { s = seaf_db_row_get_column_text (&seaf_row, 0); ret = g_strdup(s); } CATCH (SQLException) g_warning ("Error exec query %s: %s.\n", sql, Exception_frame.message); Connection_close (conn); return NULL; END_TRY; Connection_close (conn); return ret; }
BOOL CDrvDlg::OnInitDialog() { TRY CDialog::OnInitDialog(); SetIcon(m_hIcon,TRUE); SetIcon(m_hIcon,FALSE); m_FftLen.SetCurSel(0); m_OsVersion.Initialize(); DWORD platformID = m_OsVersion.GetPlatformID(); if(VER_PLATFORM_WIN32_NT == platformID) { m_SvcNew.InstallService(drvnew); m_SvcOld.InstallService(drvold); } m_DrvNew.OpenDevice(drvnew); m_DrvOld.OpenDevice(drvold); ShowCPUInfo(); ShowOSInfo(); ShowIPPSLibInfo(); UpdateData(FALSE); m_string.Format(IDS_PRG_START); WriteLog(m_string); m_string.Format(IDS_DRV_OPEN,drvold,m_DrvOld.GetDeviceHandle()); WriteLog(m_string); m_string.Format(IDS_DRV_OPEN,drvnew,m_DrvNew.GetDeviceHandle()); WriteLog(m_string); CATCH(CMyException,e); Cleanup(); e->ReportError(); END_CATCH return TRUE; } // CDrvDlg::OnInitDialog()
static INT64_T chirp_fs_confuga_pwrite(int fd, const void *buffer, INT64_T length, INT64_T offset) { int rc; size_t n; SETUP_FILE if (length < 0 || offset < 0) CATCH(EINVAL); switch (open_files[fd].type) { case CHIRP_FS_CONFUGA_FILE_WRITE: { if ((confuga_off_t)offset != open_files[fd].f.file.size) CATCH(EINVAL); /* do not allow random writes */ CATCH_CONFUGA(confuga_file_write(open_files[fd].f.file.file, buffer, length, &n, STOPTIME)); open_files[fd].f.file.size += n; break; } case CHIRP_FS_CONFUGA_META_WRITE: if ((size_t)offset != buffer_pos(&open_files[fd].f.metadata)) CATCH(EINVAL); /* do not allow random writes */ CATCHUNIX(buffer_putlstring(&open_files[fd].f.metadata, buffer, length)); n = length; break; default: CATCH(EBADF); } rc = 0; goto out; out: if (rc) { return (errno = rc, -1); } else { return n; /* N.B. return n on success */ } }
uint64_t MailboxState_getSeq(T M) { if (! M->seq) { Connection_T c = db_con_get(); TRY db_getmailbox_seq(M, c); CATCH(SQLException) LOG_SQLERROR; FINALLY db_con_close(c); END_TRY; } return M->seq; }
bool test_ascii_is_digit_hexadecimal (Test *test) { int i; TITLE (); for (i = SCHAR_MIN; i <= SCHAR_MAX; i++) { if ((char)i == '0' || (char)i == '1' || (char)i == '2' || (char)i == '3' || (char)i == '4' || (char)i == '5' || (char)i == '6' || (char)i == '7' || (char)i == '8' || (char)i == '9' || (char)i == 'a' || (char)i == 'b' || (char)i == 'c' || (char)i == 'd' || (char)i == 'e' || (char)i == 'f' || (char)i == 'A' || (char)i == 'B' || (char)i == 'C' || (char)i == 'D' || (char)i == 'E' || (char)i == 'F') { CATCH (!ascii_is_digit_hexadecimal ((char)i)); } else { CATCH (ascii_is_digit_hexadecimal ((char)i)); } } PASS (); }
int seaf_db_trans_query (SeafDBTrans *trans, const char *sql) { /* Handle zdb "exception"s. */ TRY Connection_execute (trans->conn, "%s", sql); RETURN (0); CATCH (SQLException) g_warning ("Error exec query %s: %s.\n", sql, Exception_frame.message); return -1; END_TRY; /* Should not be reached. */ return 0; }
static int resolve (confuga *C, const char *path, char resolved[CONFUGA_PATH_MAX]) { int rc; char collapse[CONFUGA_PATH_MAX]; char absolute[CONFUGA_PATH_MAX]; path_collapse(path, collapse, 1); CATCHUNIX(snprintf(absolute, sizeof(absolute), "%s/root/%s", C->root, collapse)); if ((size_t)rc >= CONFUGA_PATH_MAX) CATCH(ENAMETOOLONG); path_collapse(absolute, resolved, 1); rc = 0; goto out; out: return rc; }
void IResourceManager::onFile(const std::string &base, const std::string &file) { _base_dir = base; if (base.empty()) return; TRY { std::string preload = Finder->find(base, "preload.xml", false); if (preload.empty()) return; LOG_DEBUG(("parsing preload file: %s", preload.c_str())); PreloadParser p; p.parse_file(preload); p.update(_preload_map, _object_preload_map, base); } CATCH("parsing preload file", {}); }