gint main (gint argc, gchar **argv) { gint i, j; camel_test_init (argc, argv); camel_test_start ("references decoding"); for (i = 0; i < G_N_ELEMENTS (test1); i++) { GSList *list; camel_test_push ("references decoding[%d] '%s'", i, test1[i].header); list = camel_header_references_decode (test1[i].header); for (j = 0; test1[i].values[j]; j++) { check_msg (list != NULL, "didn't find all references"); check (strcmp (test1[i].values[j], list->data) == 0); list = g_slist_next (list); } check_msg (list == NULL, "found more references than should have"); g_slist_free_full (list, g_free); camel_test_pull (); } camel_test_end (); return 0; }
static void check_fi (CamelFolderInfo *fi, CamelFolderInfo *list, gint len) { GPtrArray *folders = g_ptr_array_new (); gint i; add_fi (folders, fi); check_msg (folders->len == len, "unexpected number of folders returned from folderinfo"); qsort (folders->pdata, folders->len, sizeof (folders->pdata[0]), cmp_fi); for (i=0;i<len;i++) { CamelFolderInfo *f = folders->pdata[i]; camel_test_push ("checking folder '%s'", list[i].uri); check_msg (!strcmp (f->uri, list[i].uri), "got '%s' expecting '%s'", f->uri, list[i].uri); check (!strcmp (f->full_name, list[i].full_name)); /* this might be translated, but we can't know */ camel_test_nonfatal ("Inbox not english"); check (!strcmp (f->name, list[i].name)); camel_test_fatal (); camel_test_nonfatal ("Flags mismatch"); check (f->flags == list[i].flags); camel_test_fatal (); camel_test_pull (); } g_ptr_array_free (folders, TRUE); }
static void test_folder_search_sub (CamelFolder *folder, const gchar *expr, gint expected) { GPtrArray *uids; GHashTable *hash; gint i; GError *error = NULL; uids = camel_folder_search_by_expression (folder, expr, NULL, &error); check (uids != NULL); check_msg (uids->len == expected, "search %s expected %d got %d", expr, expected, uids->len); check_msg (error == NULL, "%s", error->message); g_clear_error (&error); /* check the uid's are actually unique, too */ hash = g_hash_table_new (g_str_hash, g_str_equal); for (i = 0; i < uids->len; i++) { check (g_hash_table_lookup (hash, uids->pdata[i]) == NULL); g_hash_table_insert (hash, uids->pdata[i], uids->pdata[i]); } g_hash_table_destroy (hash); camel_folder_search_free (folder, uids); }
void SleepIfOkay() { // we won't sleep if the main isn't willing to block if (MQ_Main_Willing_to_block == 0) { return; } // check to see if we are handling a low priority interrupt // if so, we are not going to sleep if (in_low_int()) { return; } // we know that we are in a high priority interrupt handler // but we'll check to make sure and return if we are not if (!in_high_int()) { return; } // since we are the only thing executing that could be // putting something into a message queue destined for main() // we can safely check the message queues now // if they are empty, we'll go to sleep if (check_msg(&ToMainHigh_MQ)) { return; } if (check_msg(&ToMainLow_MQ)) { return; } enter_sleep_mode(); }
void block_on_To_msgqueues() { if (!in_main()) { return; } #ifdef __USE18F2680 LATBbits.LATB3 = 1; #endif MQ_Main_Willing_to_block = 1; while (1) { if (check_msg(&ToMainHigh_MQ)) { MQ_Main_Willing_to_block = 0; #ifdef __USE18F2680 LATBbits.LATB3 = 0; #endif return; } if (check_msg(&ToMainLow_MQ)) { MQ_Main_Willing_to_block = 0; #ifdef __USE18F2680 LATBbits.LATB3 = 0; #endif return; } Delay1KTCYx(10); #ifdef __USE18F2680 LATBbits.LATB3 = !LATBbits.LATB3; #endif } }
gint test_message_compare_content (CamelDataWrapper *dw, const gchar *text, gint len) { GByteArray *byte_array; CamelStream *stream; /* sigh, ok, so i len == 0, dw will probably be 0 too * camel_mime_part_set_content is weird like that */ if (dw == 0 && len == 0) return 0; byte_array = g_byte_array_new (); stream = camel_stream_mem_new_with_byte_array (byte_array); camel_data_wrapper_decode_to_stream_sync (dw, stream, NULL, NULL); if (byte_array->len != len) { printf ("original text:\n"); hexdump ((guchar *) text, len); printf ("new text:\n"); hexdump (byte_array->data, byte_array->len); } check_msg (byte_array->len == len, "buffer->len = %d, len = %d", byte_array->len, len); check_msg (memcmp (byte_array->data, text, byte_array->len) == 0, "len = %d", len); check_unref (stream, 1); return 0; }
int main (int argc, char **argv) { int i, j; camel_test_init(argc, argv); camel_test_start("references decoding"); for (i=0;i<sizeof(test1)/sizeof(test1[0]);i++) { struct _camel_header_references *head, *node; camel_test_push("references decoding[%d] '%s'", i, test1[i].header); head = camel_header_references_decode(test1[i].header); node = head; for (j=0;test1[i].values[j];j++) { check_msg(node != NULL, "didn't find all references"); check(strcmp(test1[i].values[j], node->id) == 0); node = node->next; } check_msg(node == NULL, "found more references than should have"); camel_header_references_list_clear(&head); camel_test_pull(); } camel_test_end(); return 0; }
void test_scan_while(){ int fd = open("scanner_test_code", O_RDONLY); check_msg(fd != -1, "failed to open the scanner_test_code file"); scanner_p scan = scan_open(fd); slice_t slice; // Throw the first two lines away scan_until(scan, &slice, '\n'); check_str(slice.ptr, "\"hello world\""); free(slice.ptr); scan_until(scan, &slice, '\n'); check_str(slice.ptr, "\t "); free(slice.ptr); int c = scan_while(scan, &slice, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); check_msg(c == '\n', "expected newline as terminator but got %d", c); check_msg(slice.length == 10, "expected length of 10 but got %d", slice.length); check_str(slice.ptr, "1234567890"); free(slice.ptr); c = scan_while(scan, &slice, '\n', '-'); check_msg(c == EOF, "expected EOF as terminator but got %d", c); check_msg(slice.length == 5, "expected length of 10 but got %d", slice.length); check_str(slice.ptr, "\n----"); free(slice.ptr); scan_close(scan); close(fd); }
// only called from "main" void block_on_To_msgqueues() { if (!in_main()) { return; } //LATBbits.LATB3 = 1; MQ_Main_Willing_to_block = 1; while (1) { if (check_msg(&ToMainHigh_MQ)) { MQ_Main_Willing_to_block = 0; //LATBbits.LATB3 = 0; return; } if (check_msg(&ToMainLow_MQ)) { MQ_Main_Willing_to_block = 0; //LATBbits.LATB3 = 0; return; } if (check_msg(&adReadQueue)) { MQ_Main_Willing_to_block = 0; //LATBbits.LATB3 = 0; return; } Delay1KTCYx(10); //LATBbits.LATB3 = !LATBbits.LATB3; } }
gint main (gint argc, gchar **argv) { gint i, j; struct _camel_search_words *words, *tmp; camel_test_init (argc, argv); camel_test_start ("Search splitting"); for (i = 0; i < G_N_ELEMENTS (split_tests); i++) { camel_test_push ("split %d '%s'", i, split_tests[i].word); words = camel_search_words_split (split_tests[i].word); check (words != NULL); check_msg (words->len == split_tests[i].count, "words->len = %d, count = %d", words->len, split_tests[i].count); for (j = 0; j < words->len; j++) { check_msg ( strcmp (split_tests[i].splits[j].word, words->words[j]->word) == 0, "'%s' != '%s'", split_tests[i].splits[j].word, words->words[j]->word); check (split_tests[i].splits[j].type == words->words[j]->type); } camel_search_words_free (words); camel_test_pull (); } camel_test_end (); camel_test_start ("Search splitting - simple"); for (i = 0; i < G_N_ELEMENTS (simple_tests); i++) { camel_test_push ("simple split %d '%s'", i, simple_tests[i].word); tmp = camel_search_words_split (simple_tests[i].word); check (tmp != NULL); words = camel_search_words_simple (tmp); check (words != NULL); check_msg (words->len == simple_tests[i].count, "words->len = %d, count = %d", words->len, simple_tests[i].count); for (j = 0; j < words->len; j++) { check_msg ( strcmp (simple_tests[i].splits[j].word, words->words[j]->word) == 0, "'%s' != '%s'", simple_tests[i].splits[j].word, words->words[j]->word); check (simple_tests[i].splits[j].type == words->words[j]->type); } camel_search_words_free (words); camel_search_words_free (tmp); camel_test_pull (); } camel_test_end (); return 0; }
gint test_message_compare (CamelMimeMessage *msg) { CamelMimeMessage *msg2; CamelStream *stream1; CamelStream *stream2; GByteArray *byte_array1; GByteArray *byte_array2; byte_array1 = g_byte_array_new (); stream1 = camel_stream_mem_new_with_byte_array (byte_array1); check_msg (camel_data_wrapper_write_to_stream_sync ( CAMEL_DATA_WRAPPER (msg), stream1, NULL, NULL) != -1, "write_to_stream 1 failed", NULL); g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL); msg2 = camel_mime_message_new (); check_msg (camel_data_wrapper_construct_from_stream_sync ( CAMEL_DATA_WRAPPER (msg2), stream1, NULL, NULL) != -1, "construct_from_stream 1 failed"); g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL); byte_array2 = g_byte_array_new (); stream2 = camel_stream_mem_new_with_byte_array (byte_array2); check_msg (camel_data_wrapper_write_to_stream_sync ( CAMEL_DATA_WRAPPER (msg2), stream2, NULL, NULL) != -1, "write_to_stream 2 failed"); g_seekable_seek (G_SEEKABLE (stream2), 0, G_SEEK_SET, NULL, NULL); if (byte_array1->len != byte_array2->len) { CamelDataWrapper *content; printf ("stream1 stream:\n%.*s\n", byte_array1->len, byte_array1->data); printf ("stream2 stream:\n%.*s\n\n", byte_array2->len, byte_array2->data); printf ("msg1:\n"); test_message_dump_structure (msg); printf ("msg2:\n"); test_message_dump_structure (msg2); content = camel_medium_get_content ((CamelMedium *) msg); } check_unref (msg2, 1); check_msg ( byte_array1->len == byte_array2->len, "byte_array1->len = %d, byte_array2->len = %d", byte_array1->len, byte_array2->len); check_msg (memcmp (byte_array1->data, byte_array2->data, byte_array1->len) == 0, "msg/stream compare"); g_object_unref (stream1); g_object_unref (stream2); return 0; }
void test_scan_until_func(){ int fd = open("scanner_test_code", O_RDONLY); check_msg(fd != -1, "failed to open the scanner_test_code file"); scanner_p scan = scan_open(fd); slice_t slice; int c = scan_until_func(scan, &slice, isspace); check_msg(c == ' ', "expected a space as terminator but got %d", c); check_msg(slice.length == 6, "expected length of 6 but got %d", slice.length); check_str(slice.ptr, "\"hello"); free(slice.ptr); scan_close(scan); close(fd); }
void test_scan_while_func(){ int fd = open("scanner_test_code", O_RDONLY); check_msg(fd != -1, "failed to open the scanner_test_code file"); scanner_p scan = scan_open(fd); slice_t slice; int c = scan_while_func(scan, &slice, ispunct, islower, isblank); check_msg(c == '\n', "expected newline as terminator but got %c", c); check_msg(slice.length == 13, "expected length of 13 but got %d", slice.length); check_str(slice.ptr, "\"hello world\""); free(slice.ptr); scan_close(scan); close(fd); }
static int cb (struct skynet_context *ctx, void *ud, int type, int session, uint32_t source, const void *msg, size_t sz) { int priority = LOG_WARNING; const char *str = check_msg ((const char *)msg, sz, &priority); syslog (priority, "[:%08x] %s", source, str); return 0; }
int bbsmsg_main() { //modify by mintbaggio 20040829 for new www char buf[MAX_MSG_SIZE]; char msgbuf[MAX_MSG_SIZE*2]; int count, i; struct msghead head; html_header(1); check_msg(); printf("<body>"); printf("<div class=rhead>%s -- 查看信息</div><hr>\n", BBSNAME); if (!loginok || isguest) http_fatal("匆匆过客无法查看讯息, 请先登录"); changemode(LOOKMSGS); count = get_msgcount(0, currentuser.userid); if (count == 0) http_fatal("没有任何讯息"); for (i=0; i<count; i++) { load_msghead(0, currentuser.userid, &head, i); load_msgtext(currentuser.userid, &head, buf); translate_msg(buf, &head, msgbuf, 0); hprintf("%s", msgbuf); } u_info->unreadmsg = 0; printf("<a onclick='return confirm(\"你真的要清除所有讯息吗?\")' href=bbsdelmsg>清除所有讯息</a> "); printf("<a href=bbsmailmsg>寄回所有信息</a>"); http_quit(); return 0; }
static SoupMessage* send_msg_to_server (OGDProvider *provider, const gchar *complete_query, GError **error) { guint sendret; SoupMessage *msg; msg = soup_message_new ("GET", complete_query); if (msg == NULL) { g_set_error (error, OGD_NETWORK_ERROR_DOMAIN, OGD_NETWORK_ERROR, "Unable to build request to server"); return NULL; } sendret = soup_session_send_message (provider->priv->http_session, msg); if (sendret != 200) { g_set_error (error, OGD_NETWORK_ERROR_DOMAIN, OGD_NETWORK_ERROR, "Unable to send request to server, error %u", sendret); g_object_unref (msg); return NULL; } if (check_msg (msg, error) == FALSE) return NULL; else return msg; }
void test_read_data_size_with_full_buffer() { uint64_t samples[] = { 1, 126, 16382, 2097150, 268435454, 34359738366, 4398046511102, 562949953421310, 72057594037927934 }; char* buffer = NULL; size_t buffer_size = 0, pos = 0; FILE* f = open_memstream(&buffer, &buffer_size); for(size_t i = 0; i < sizeof(samples) / sizeof(samples[0]); i++) ebml_write_data_size(f, samples[i], 0); fclose(f); for(size_t i = 0; i < sizeof(samples) / sizeof(samples[0]); i++) { uint64_t value = ebml_read_data_size(buffer + pos, buffer_size - pos, &pos); check_msg(value == samples[i], "got %llu, expected %llu\n", value, samples[i]); } check_int(pos, buffer_size); }
int main(int argc, char **argv) { char *msg; int key[4]; int flag; int *res; size_t msg_len; if (argc == 8) { flag = atoi(argv[7]); if (check_base(argv[6])) { if ((flag == 0 && (msg = check_msg(argv[1]))) || (flag == 1 && (msg = check_msg_base(argv[1], argv[6])))) { if (get_key(argv[2], argv[3], argv[4], argv[5], key)) { if (flag == 1) inv_key(key); res = cypher(msg, key, flag, argv[6], &msg_len); if (flag) inv_key(key); print_msg(argv[1], key, argv[6], res, flag, msg_len); free(res); return (0); } } } printf("Invalid args\n"); } else usage(); return (0); }
int bbseva_main() { char board[80], file[80]; int star; html_header(1); check_msg(); strsncpy(board, getparm("B"), 32); if (!board[0]) strsncpy(board, getparm("board"), 32); strsncpy(file, getparm("F"), 20); if (!file[0]) strsncpy(file, getparm("file"), 32); star = atoi(getparm("star")); if (!loginok) http_fatal("匆匆过客不能进行本项操作"); changemode(READING); if(! getboard(board)) http_fatal("错误的讨论区"); if (hideboard(board)) http_fatal("隐藏版面就不要评价文章啦!"); if (star < 1 || star > 5) http_fatal("错误的参数"); if (star == 1) star++; printf("<center>%s -- 评价文章 [使用者: %s]<hr>\n", BBSNAME, currentuser.userid); printf("<table><td>"); do_eva(board, file, star); printf("</td></table>"); printf("[<a href='javascript:history.go(-1)'>返回</a>]"); http_quit(); return 0; }
int bbsparm_main() { ////modify by mintbaggio 20040829 for new www int i, perm = 1, type; html_header(1); check_msg(); type = atoi(getparm("type")); printf("<body><center><div class=rhead>%s -- 修改个人参数 [使用者: <span class=h11>%s</span>]</div><hr>\n", BBSNAME, currentuser.userid); if (!loginok || isguest) http_fatal("匆匆过客不能设定参数"); changemode(USERDEF); if (type) return read_form(); printf("<form action=bbsparm?type=1 method=post>\n"); printf("<table>\n"); for (i = 0; defines[i]; i++) { char *ptr = ""; if (i % 2 == 0) printf("<tr>\n"); if (currentuser.userdefine & perm) ptr = " checked"; printf ("<td><input type=checkbox name=perm%d%s></td><td>%s</td>", i, ptr, defines[i]); perm = perm * 2; } printf("</table>"); printf ("<input type=submit value=确定修改></form><br>以上参数大多仅在telnet方式下才有作用\n"); printf("</body>"); http_quit(); return 0; }
static void test_add_message (CamelFolder *folder, gint j) { CamelMimeMessage *msg; gchar *content; gchar *subject; GError *error = NULL; push ("creating message %d\n", j); msg = test_message_create_simple (); content = g_strdup_printf ("Test message %08x contents\n\n", j); test_message_set_content_simple ( (CamelMimePart *) msg, 0, "text/plain", content, strlen (content)); test_free (content); subject = g_strdup_printf ("Test message %08x subject", j); camel_mime_message_set_subject (msg, subject); pull (); push ("appending simple message %d", j); camel_folder_append_message_sync ( folder, msg, NULL, NULL, NULL, &error); check_msg (error == NULL, "%s", error->message); g_clear_error (&error); pull (); check_unref (msg, 1); }
int bbsfall_main() { int i; html_header(1); check_msg(); if (!loginok || isguest) http_fatal("дЗипн╢╣гб╪, гКох╣гб╪"); changemode(GMENU); loadfriend(currentuser->userid); printf("<body><center>\n"); printf("%s -- ╨цсяцШ╣╔ [й╧сцуъ: %s]<hr><br>\n", BBSNAME, currentuser->userid); printf("дЗ╧╡иХ╤╗ак %d н╩╨цся<br>", friendnum); printf ("<table border=1><tr><td>пР╨е</td><td>╨цся╢З╨е</td><td>╨цсяк╣цВ</td><td>и╬ЁЩ╨цся</td></tr>"); for (i = 0; i < friendnum; i++) { printf("<tr><td>%d</td>", i + 1); printf("<td><a href=bbsqry?userid=%s>%s</a></td>", fff[i].id, fff[i].id); printf("<td>%s</td>\n", nohtml(fff[i].exp)); printf ("<td>[<a onclick='return confirm(\"х╥й╣и╬ЁЩбП?\")' href=bbsfdel?userid=%s>и╬ЁЩ</a>]</td></tr>", fff[i].id); } printf("</table><hr>\n"); printf("[<a href=bbsfadd>лМ╪спб╣д╨цся</a>]</center></body>\n"); http_quit(); return 0; }
void test_address_compare(CamelInternetAddress *addr, CamelInternetAddress *addr2) { const char *r1, *r2, *a1, *a2; char *e1, *e2, *f1, *f2; int j; check(camel_address_length(CAMEL_ADDRESS(addr)) == camel_address_length(CAMEL_ADDRESS(addr2))); for (j=0;j<camel_address_length(CAMEL_ADDRESS(addr));j++) { check(camel_internet_address_get(addr, j, &r1, &a1) == TRUE); check(camel_internet_address_get(addr2, j, &r2, &a2) == TRUE); check(string_equal(r1, r2)); check(strcmp(a1, a2) == 0); } check(camel_internet_address_get(addr, j, &r1, &a1) == FALSE); check(camel_internet_address_get(addr2, j, &r2, &a2) == FALSE); e1 = camel_address_encode(CAMEL_ADDRESS(addr)); e2 = camel_address_encode(CAMEL_ADDRESS(addr2)); if (camel_address_length(CAMEL_ADDRESS(addr)) == 0) check(e1 == NULL && e2 == NULL); else check(e1 != NULL && e2 != NULL); if (e1 != NULL) { check_msg(string_equal(e1, e2), "e1 = '%s' e2 = '%s'", e1, e2); test_free(e1); test_free(e2); } f1 = camel_address_format(CAMEL_ADDRESS(addr)); f2 = camel_address_format(CAMEL_ADDRESS(addr2)); if (camel_address_length(CAMEL_ADDRESS(addr)) == 0) check(f1 == NULL && f2 == NULL); else check(f1 != NULL && f2 != NULL); if (f1 != NULL) { check_msg(string_equal(f1, f2), "f1 = '%s' f2 = '%s'", f1, f2); test_free(f1); test_free(f2); } }
static short check_all_msg (ATTACHPTR ** idx, short idxlen, BODY * cur, short err) { short i; if (cur && check_msg (cur, err) == -1) return -1; else if (!cur) { for (i = 0; i < idxlen; i++) { if (idx[i]->content->tagged) { if (check_msg (idx[i]->content, err) == -1) return -1; } } } return 0; }
static int handle_cmd(void *data, void *buf, size_t size) { struct sap_message *msg = buf; struct sap_connection *conn = data; if (!conn) return -EINVAL; if (size < sizeof(struct sap_message)) goto error_rsp; if (msg->nparam != 0 && size < (sizeof(struct sap_message) + sizeof(struct sap_parameter) + 4)) goto error_rsp; if (check_msg(msg) < 0) goto error_rsp; DBG("Msg id = %x",msg->id); switch (msg->id) { case SAP_CONNECT_REQ: connect_req(conn, msg->param); return 0; case SAP_DISCONNECT_REQ: disconnect_req(conn, SAP_DISCONNECTION_TYPE_CLIENT); return 0; case SAP_TRANSFER_APDU_REQ: transfer_apdu_req(conn, msg->param); return 0; case SAP_TRANSFER_ATR_REQ: transfer_atr_req(conn); return 0; case SAP_POWER_SIM_OFF_REQ: power_sim_off_req(conn); return 0; case SAP_POWER_SIM_ON_REQ: power_sim_on_req(conn); return 0; case SAP_RESET_SIM_REQ: reset_sim_req(conn); return 0; case SAP_TRANSFER_CARD_READER_STATUS_REQ: transfer_card_reader_status_req(conn); return 0; case SAP_SET_TRANSPORT_PROTOCOL_REQ: set_transport_protocol_req(conn, msg->param); return 0; default: DBG("SAP unknown message."); break; } error_rsp: DBG("Bad request message format."); sap_error_rsp(conn); return -EBADMSG; }
/* check a message is present */ void test_folder_message (CamelFolder *folder, const gchar *uid) { CamelMimeMessage *msg; CamelMessageInfo *info; GPtrArray *s; gint i; gint found; GError *error = NULL; push ("uid %s is in folder", uid); /* first try getting info */ info = camel_folder_get_message_info (folder, uid); check (info != NULL); check (strcmp (camel_message_info_get_uid (info), uid) == 0); camel_message_info_unref (info); /* then, getting message */ msg = camel_folder_get_message_sync (folder, uid, NULL, &error); check_msg (error == NULL, "%s", error->message); check (msg != NULL); /* cross check with info */ test_message_info (msg, info); g_object_unref (msg); /* see if it is in the summary (only once) */ s = camel_folder_get_summary (folder); check (s != NULL); found = 0; for (i = 0; i < s->len; i++) { info = s->pdata[i]; if (strcmp (camel_message_info_get_uid (info), uid) == 0) found++; } check (found == 1); camel_folder_free_summary (folder, s); /* check it is in the uid list */ s = camel_folder_get_uids (folder); check (s != NULL); found = 0; for (i = 0; i < s->len; i++) { if (strcmp (s->pdata[i], uid) == 0) found++; } check (found == 1); camel_folder_free_uids (folder, s); g_clear_error (&error); pull (); }
static void check_address_line_decode (gint i, const gchar *line, const gchar *name, const gchar *email) { CamelInternetAddress *addr; const gchar *dname, *demail; push ("Testing address line %d '%s'", i, line); dname = NULL; demail = NULL; addr = camel_internet_address_new (); check (camel_address_decode (CAMEL_ADDRESS (addr), line) == 1); check (camel_internet_address_get (CAMEL_INTERNET_ADDRESS (addr), 0, &dname, &demail)); check_msg (g_strcmp0 (dname, name) == 0 || (!name && dname && !*dname), "decoded name = '%s', but should be '%s'", dname, name); check_msg (g_strcmp0 (demail, email) == 0, "decoded email = '%s', but should be '%s'", demail, email); check_unref (addr, 1); pull (); }
void test_string_scanner(){ scanner_p scan = scan_open_string("say(hello)"); slice_t slice; int c = scan_while_func(scan, &slice, isalpha); check_msg(c == '(', "expected ( as terminator but got %c", c); check_msg(slice.length == 3, "expected 3 characters for the first word but got length %d", slice.length); check_str(slice.ptr, "say"); free(slice.ptr); c = scan_one_of(scan, '('); check_msg(c == '(', "somehow reading the opening braces failed, got %c", c); c = scan_until(scan, &slice, ')'); check_msg(c == ')', "expected ) as terminator but got %c", c); check_str(slice.ptr, "hello"); free(slice.ptr); c = scan_until(scan, &slice, EOF); check_msg(c == EOF, "expected EOF as terminator but got %d", c); check_msg(slice.length == 0, "expected an empty string until EOF but got length %d", slice.length); check_str(slice.ptr, ""); free(slice.ptr); scan_close(scan); }
void test_scan_until(){ int fd = open("scanner_test_code", O_RDONLY); check_msg(fd != -1, "failed to open the scanner_test_code file"); scanner_p scan = scan_open(fd); slice_t slice; int c = scan_until(scan, &slice, '"'); check_msg(c == '"', "expected terminator \" but got %c (%d)", c, c); check_msg(slice.length == 0, "expected length of 0 but got %d", slice.length); check_str(slice.ptr, ""); free(slice.ptr); c = scan_until(scan, &slice, '"'); check_msg(c == '"', "expected terminator \" but got %c (%d)", c, c); check_msg(slice.length == 11, "expected length of 11 but got %d", slice.length); check_str(slice.ptr, "hello world"); free(slice.ptr); c = scan_until(scan, &slice, EOF); check_msg(c == EOF, "expected terminator EOF but got %d", c); check_str(slice.ptr, "\n\t \n1234567890\n----"); free(slice.ptr); scan_close(scan); close(fd); }
int bbsdenyadd_main() { int i; char exp[80], board[80], *userid; int dt; struct userec *x; struct boardmem *x1; html_header(1); check_msg(); if (!loginok || isguest) http_fatal("您尚未登录, 请先登录"); changemode(READING); getparmboard(board, sizeof(board)); strsncpy(exp, getparm("exp"), 30); dt = atoi(getparm("dt")); if (!(x1 = getboard(board))) http_fatal("错误的讨论区"); if (!has_BM_perm(currentuser, x1)) http_fatal("你无权进行本操作"); loaddenyuser(board); userid = getparm("userid"); if (userid[0] == 0) return show_form(board); if (getuser(userid, &x) <= 0) http_fatal("错误的使用者帐号"); if (!has_post_perm(x, x1)) http_fatal("这个人本来就没有post权"); strcpy(userid, x->userid); if (!(currentuser->userlevel & PERM_SYSOP) && (dt > 14)) http_fatal("封禁时间大于14天,超过了权限,若需要,请联系站长"); if (dt < 1 || dt > 99) http_fatal("请输入被封天数(1-99)"); if (exp[0] == 0) http_fatal("请输入封人原因"); for (i = 0; i < denynum; i++) if (!strcasecmp(denyuser[i].id, userid)) http_fatal("此用户已经被封"); if (denynum > 40) http_fatal("太多人被封了"); strsncpy(denyuser[denynum].id, userid, 13); strsncpy(denyuser[denynum].exp, exp, 30); denyuser[denynum].free_time = now_t + dt * 86400; denynum++; savedenyuser(board); printf("封禁 %s 成功<br>\n", userid); tracelog("%s deny %s %s", currentuser->userid, board, userid); inform(board, userid, exp, dt); printf("[<a href=bbsdenyall?B=%d>返回被封帐号名单</a>]", getbnumx(x1)); http_quit(); return 0; }