int main () { int i; test_addl_S64_S32_4 (S64_ta, S32_tb, S32_tc); SCHECK (64, 4, addl); test_addl_S32_S16_8 (S32_ta, S16_tb, S16_tc); SCHECK (32, 8, addl); test_addl_S16_S8_16 (S16_ta, S8_tb, S8_tc); SCHECK (16, 16, addl); test_subl_S64_S32_4 (S64_ta, S32_tb, S32_tc); SCHECK (64, 4, subl); test_subl_S32_S16_8 (S32_ta, S16_tb, S16_tc); SCHECK (32, 8, subl); test_subl_S16_S8_16 (S16_ta, S8_tb, S8_tc); SCHECK (16, 16, subl); test_addl_U64_U32_4 (S64_ta, S32_tb, S32_tc); UCHECK (64, 4, addl); test_addl_U32_U16_8 (S32_ta, S16_tb, S16_tc); UCHECK (32, 8, addl); test_addl_U16_U8_16 (S16_ta, S8_tb, S8_tc); UCHECK (16, 16, addl); test_subl_U64_U32_4 (S64_ta, S32_tb, S32_tc); UCHECK (64, 4, subl); test_subl_U32_U16_8 (S32_ta, S16_tb, S16_tc); UCHECK (32, 8, subl); test_subl_U16_U8_16 (S16_ta, S8_tb, S8_tc); UCHECK (16, 16, subl); test_addl_S64_S32_4_neg0 (S64_ta, S32_tb, S32_tc); NCHECK (neg_r); test_addl_S64_S32_4_neg1 (S64_ta, S32_tb, S32_tc); NCHECK (subl_rS64); test_subl_S64_S32_4_neg0 (S64_ta, S32_tb, S32_tc); NCHECK (addl_rS64); test_subl_S64_S32_4_neg1 (S64_ta, S32_tb, S32_tc); NCHECK (neg_r); test_subl_S64_S32_4_neg2 (S64_ta, S32_tb, S32_tc); NCHECK (neg_r); return 0; }
EStatus StationSendAck(Station* pThis, const Packet* pPacket) { Packet* pAck; ListEntry* pEntry; if (!StationIsAckRequired(pThis, pPacket)) return eSTATUS_COMMON_OK; NCHECK(ListFind(pThis->pOutbox, &pEntry, (ItemComparator)&StationAckFinder, (void*)pPacket, pThis)); CHECK(PacketNewAck(&pAck, pThis->id, pPacket->header.transitSrcId)); pAck->header.sequenceNum = pPacket->header.sequenceNum; return StationSendPacket(pThis, pAck); }
int NC4_get_fileinfo(NC_HDF5_FILE_INFO_T* h5, struct NCPROPINFO* init) { int ncstat = NC_NOERR; /* Allocate the fileinfo in h5 */ h5->fileinfo = (struct NCFILEINFO*)calloc(1,sizeof(struct NCFILEINFO)); if(h5->fileinfo == NULL) {ncstat = NC_ENOMEM; goto done;} /* Get superblock version */ NCHECK((ncstat = NC4_hdf5get_superblock(h5,&h5->fileinfo->superblockversion))); /* Get properties attribute if not already defined */ if(init == NULL) { NCHECK((ncstat = NC4_get_propattr(h5))); } else { /*init != NULL*/ h5->fileinfo->propattr = *init; /* Initialize */ } done: return ncstat; }
int main () { int i; test_addS64_tS32_t4 (S64_ta, S32_tb, S32_tc); SCHECK (64, 4, add); test_addS32_tS16_t8 (S32_ta, S16_tb, S16_tc); SCHECK (32, 8, add); test_addS16_tS8_t16 (S16_ta, S8_tb, S8_tc); SCHECK (16, 16, add); test_subS64_tS32_t4 (S64_ta, S32_tb, S32_tc); SCHECK (64, 4, sub); test_subS32_tS16_t8 (S32_ta, S16_tb, S16_tc); SCHECK (32, 8, sub); test_subS16_tS8_t16 (S16_ta, S8_tb, S8_tc); SCHECK (16, 16, sub); test_addU64_tU32_t4 (S64_ta, S32_tb, S32_tc); UCHECK (64, 4, add); test_addU32_tU16_t8 (S32_ta, S16_tb, S16_tc); UCHECK (32, 8, add); test_addU16_tU8_t16 (S16_ta, S8_tb, S8_tc); UCHECK (16, 16, add); test_subU64_tU32_t4 (S64_ta, S32_tb, S32_tc); UCHECK (64, 4, sub); test_subU32_tU16_t8 (S32_ta, S16_tb, S16_tc); UCHECK (32, 8, sub); test_subU16_tU8_t16 (S16_ta, S8_tb, S8_tc); UCHECK (16, 16, sub); test_addS16_tS8_t16_neg0 (S16_ta, S8_tb, S8_tc); NCHECK (add_rS16); test_subS16_tS8_t16_neg0 (S16_ta, S8_tb, S8_tc); NCHECK (sub_rS16); test_addS16_tS8_t16_neg1 (S16_ta, S8_tb, S8_tc); NCHECK (add_rS16); test_subS16_tS8_t16_neg1 (S16_ta, S8_tb, S8_tc); NCHECK (sub_rS16); test_addS16_tS8_t16_neg2 (S16_ta, S8_tb, S8_tc); NCHECK (add_rS16); test_subS16_tS8_t16_neg2 (S16_ta, S8_tb, S8_tc); NCHECK (sub_rS16); test_subS16_tS8_t16_neg3 (S16_ta, S8_tb, S8_tc); NCHECK (neg_r); return 0; }
static void regular_test(struct mem_allocator* allocator) { char dump[BUFSIZ]; void* p = NULL; void* q[3] = {NULL, NULL, NULL}; size_t i = 0; p = MEM_ALIGNED_ALLOC(allocator, 1024, ALIGNOF(char)); NCHECK(p, NULL); CHECK(IS_ALIGNED((uintptr_t)p, ALIGNOF(char)), 1); MEM_FREE(allocator, p); q[0] = MEM_ALIGNED_ALLOC(allocator, 10, 8); q[1] = MEM_CALLOC(allocator, 1, 58); q[2] = MEM_ALLOC(allocator, 78); NCHECK(q[0], NULL); NCHECK(q[1], NULL); NCHECK(q[2], NULL); CHECK(IS_ALIGNED((uintptr_t)q[0], 8), 1); p = MEM_CALLOC(allocator, 2, 2); NCHECK(p, NULL); for(i = 0; i < 4; ++i) CHECK(((char*)p)[i], 0); for(i = 0; i < 4; ++i) ((char*)p)[i] = (char)i; MEM_DUMP(allocator, dump, BUFSIZ); printf("dump:\n%s\n", dump); MEM_DUMP(allocator, dump, 16); printf("truncated dump:\n%s\n", dump); MEM_DUMP(allocator, NULL, 0); /* may not crashed. */ MEM_FREE(allocator, q[1]); p = MEM_REALLOC(allocator, p, 8); for(i = 0; i < 4; ++i) CHECK(((char*)p)[i], (char)i); for(i = 4; i < 8; ++i) ((char*)p)[i] = (char)i; MEM_FREE(allocator, q[2]); p = MEM_REALLOC(allocator, p, 5); for(i = 0; i < 5; ++i) CHECK(((char*)p)[i], (char)i); MEM_FREE(allocator, p); p = NULL; p = MEM_REALLOC(allocator, NULL, 16); NCHECK(p, NULL); p = MEM_REALLOC(allocator, p, 0); MEM_FREE(allocator, q[0]); CHECK(MEM_ALIGNED_ALLOC(allocator, 1024, 0), NULL); CHECK(MEM_ALIGNED_ALLOC(allocator, 1024, 3), NULL); CHECK(MEM_ALLOCATED_SIZE(allocator), 0); }
int main(int argc, char** argv) { /* Check command arguments */ if(argc != 3) { printf("usage: %s RB_DRIVER FONT\n", argv[0]); return -1; } const char* driver_name = argv[1]; const char* font_name = argv[2]; FILE* file = fopen(driver_name, "r"); if(!file) { fprintf(stderr, "Invalid driver %s\n", driver_name); return -1; } fclose(file); file = fopen(font_name, "r"); if(!file) { fprintf(stderr, "Invalid font name %s\n", font_name); return -1; } fclose(file); /* Spawn a drawable windows */ struct wm_device* device = NULL; struct wm_window* window = NULL; const struct wm_window_desc win_desc = { .width = 640, .height = 480, .fullscreen = false }; WM(create_device(NULL, &device)); WM(create_window(device, &win_desc, &window)); /* Create a render backend */ struct rbi rbi; struct rb_context* rb_ctxt = NULL; CHECK(rbi_init(driver_name, &rbi), 0); RBI(&rbi, create_context(NULL, &rb_ctxt)); /* Load font resource */ struct font_system* font_sys = NULL; struct font_rsrc* font_rsrc = NULL; bool is_font_scalable = false; int line_space = 0; FONT(system_create(NULL, &font_sys)); FONT(rsrc_create(font_sys, font_name, &font_rsrc)); FONT(rsrc_get_line_space(font_rsrc, &line_space)); FONT(rsrc_is_scalable(font_rsrc, &is_font_scalable)); if(is_font_scalable) { FONT(rsrc_set_size(font_rsrc, 24, 24)); } /* Build x charset description */ int glyph_min_width = INT_MAX; const wchar_t* charset = L"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" L" &~\"#'{([-|`_\\^@)]=}+$%*,?;.:/!<>"; const size_t charset_len = wcslen(charset); size_t i = 0; struct lp_font_glyph_desc lp_font_glyph_desc_list[512]; unsigned char* glyph_bitmap_list[512]; ASSERT(charset_len <= 512); for(i = 0; i < charset_len; ++i) { struct font_glyph_desc font_glyph_desc; struct font_glyph* font_glyph = NULL; int width = 0; int height = 0; int Bpp = 0; FONT(rsrc_get_glyph(font_rsrc, charset[i], &font_glyph)); FONT(glyph_get_desc(font_glyph, &font_glyph_desc)); glyph_min_width = MIN(font_glyph_desc.width, glyph_min_width); lp_font_glyph_desc_list[i].width = font_glyph_desc.width; lp_font_glyph_desc_list[i].character = font_glyph_desc.character; lp_font_glyph_desc_list[i].bitmap_left = font_glyph_desc.bbox.x_min; lp_font_glyph_desc_list[i].bitmap_top = font_glyph_desc.bbox.y_min; FONT(glyph_get_bitmap(font_glyph, true, &width, &height, &Bpp, NULL)); if(width && height ) { glyph_bitmap_list[i] = MEM_CALLOC (&mem_default_allocator, (size_t)(width*height), (size_t)Bpp); NCHECK(glyph_bitmap_list[i], NULL); FONT(glyph_get_bitmap (font_glyph, true, &width, &height, &Bpp, glyph_bitmap_list[i])); } lp_font_glyph_desc_list[i].bitmap.width = width; lp_font_glyph_desc_list[i].bitmap.height = height; lp_font_glyph_desc_list[i].bitmap.bytes_per_pixel = Bpp; lp_font_glyph_desc_list[i].bitmap.buffer = glyph_bitmap_list[i]; FONT(glyph_ref_put(font_glyph)); } /* Create the lp system and font */ struct lp* lp = NULL; struct lp_font* lp_font = NULL; LP(create(&rbi, rb_ctxt, NULL, &lp)); LP(font_create(lp, &lp_font)); LP(font_set_data (lp_font, line_space, (int)charset_len, lp_font_glyph_desc_list)); /* Create the printer */ struct lp_printer* lp_printer = NULL; LP(printer_create(lp, &lp_printer)); LP(printer_set_font(lp_printer, lp_font)); LP(printer_set_viewport(lp_printer, 0, 0, win_desc.width, win_desc.height)); enum wm_state esc = WM_STATE_UNKNOWN; do { int cur[2] = { 0, 0 }; RBI(&rbi, clear (rb_ctxt, RB_CLEAR_COLOR_BIT, (float[]){0.05f, 0.05f, 0.05f}, 0.f, 0)); LP(printer_print_wstring (lp_printer, 50, 70, L">$ ", (float[]){0.f, 1.f, 0.f}, cur+0, cur+1)); LP(printer_print_wstring (lp_printer, cur[0], cur[1], L"Hello", (float[]){1.f, 1.f, 1.f}, cur+0, cur+1));
int main(int argc, char** argv) { char buf[BUFSIZ]; struct font_glyph_desc desc; struct font_system* sys = NULL; struct font_rsrc* font = NULL; struct font_glyph* glyph = NULL; const char* path = NULL; unsigned char* buffer = NULL; size_t buffer_size = 0; int h = 0; int w = 0; int Bpp = 0; int i = 0; bool b = false; if(argc != 2) { printf("usage: %s FONT\n", argv[0]); goto error; } path = argv[1]; CHECK(font_system_create( NULL, NULL ), BAD_ARG); CHECK(font_system_create(NULL, &sys), OK); CHECK(font_rsrc_create(NULL, NULL, NULL), BAD_ARG); CHECK(font_rsrc_create(sys, NULL, NULL), BAD_ARG); CHECK(font_rsrc_create(NULL, NULL, &font), BAD_ARG); CHECK(font_rsrc_create(sys, NULL, &font), OK); CHECK(font_rsrc_load(NULL, NULL), BAD_ARG); CHECK(font_rsrc_load(font, NULL), BAD_ARG); CHECK(font_rsrc_load(NULL, path), BAD_ARG); CHECK(font_rsrc_load(font, path), OK); CHECK(font_rsrc_is_scalable(NULL, NULL), BAD_ARG); CHECK(font_rsrc_is_scalable(font, NULL), BAD_ARG); CHECK(font_rsrc_is_scalable(NULL, &b), BAD_ARG); CHECK(font_rsrc_is_scalable(font, &b), OK); if(b) { CHECK(font_rsrc_set_size(NULL, 0, 0), BAD_ARG); CHECK(font_rsrc_set_size(font, 0, 0), BAD_ARG); CHECK(font_rsrc_set_size(NULL, 32, 0), BAD_ARG); CHECK(font_rsrc_set_size(font, 32, 0), BAD_ARG); CHECK(font_rsrc_set_size(NULL, 0, 64), BAD_ARG); CHECK(font_rsrc_set_size(font, 0, 64), BAD_ARG); CHECK(font_rsrc_set_size(NULL, 32, 64), BAD_ARG); CHECK(font_rsrc_set_size(font, 32, 64), OK); CHECK(font_rsrc_set_size(font, 16, 16), OK); } CHECK(font_rsrc_get_line_space(NULL, NULL), BAD_ARG); CHECK(font_rsrc_get_line_space(font, NULL), BAD_ARG); CHECK(font_rsrc_get_line_space(NULL, &i), BAD_ARG); CHECK(font_rsrc_get_line_space(font, &i), OK); CHECK(font_rsrc_get_glyph(NULL, L'a', NULL), BAD_ARG); CHECK(font_rsrc_get_glyph(font, L'a', NULL), BAD_ARG); CHECK(font_rsrc_get_glyph(NULL, L'a', &glyph), BAD_ARG); CHECK(font_rsrc_get_glyph(font, L'a', &glyph), OK); CHECK(font_glyph_get_desc(NULL, NULL), BAD_ARG); CHECK(font_glyph_get_desc(glyph, NULL), BAD_ARG); CHECK(font_glyph_get_desc(NULL, &desc), BAD_ARG); CHECK(font_glyph_get_desc(glyph, &desc), OK); CHECK(desc.character, L'a'); CHECK(font_glyph_get_bitmap(NULL, true, NULL, NULL, NULL, NULL), BAD_ARG); CHECK(font_glyph_get_bitmap(glyph, true, NULL, NULL, NULL, NULL), OK); CHECK(font_glyph_get_bitmap(glyph, true, &w, NULL, NULL, NULL), OK); CHECK(font_glyph_get_bitmap(glyph, true, NULL, &h, NULL, NULL), OK); CHECK(font_glyph_get_bitmap(glyph, true, &w, &h, NULL, NULL), OK); CHECK(font_glyph_get_bitmap(glyph, true, NULL, NULL, &Bpp, NULL), OK); CHECK(font_glyph_get_bitmap(glyph, true, &w, NULL, &Bpp, NULL), OK); CHECK(font_glyph_get_bitmap(glyph, true, NULL, &h, &Bpp, NULL), OK); CHECK(font_glyph_get_bitmap(glyph, true, &w, &h, &Bpp, NULL), OK); NCHECK(w, 0); NCHECK(h, 0); NCHECK(Bpp, 0); buffer = MEM_CALLOC (&mem_default_allocator, (size_t)(w*h*Bpp), sizeof(unsigned char)); NCHECK(buffer, NULL); buffer_size = (size_t)(w*h*Bpp) * sizeof(unsigned char); CHECK(font_glyph_get_bitmap(glyph, false, NULL, NULL, NULL, buffer), OK); CHECK(font_glyph_get_bitmap(glyph, false, &w, NULL, NULL, buffer), OK); CHECK(font_glyph_get_bitmap(glyph, false, NULL, &h, NULL, buffer), OK); CHECK(font_glyph_get_bitmap(glyph, false, &w, &h, NULL, buffer), OK); CHECK(font_glyph_get_bitmap(glyph, false, NULL, NULL, &Bpp, buffer), OK); CHECK(font_glyph_get_bitmap(glyph, false, &w, NULL, &Bpp, buffer), OK); CHECK(font_glyph_get_bitmap(glyph, false, NULL, &h, &Bpp, buffer), OK); CHECK(font_glyph_get_bitmap(glyph, false, &w, &h, &Bpp, buffer), OK); CHECK(font_glyph_ref_get(NULL), BAD_ARG); CHECK(font_glyph_ref_get(glyph), OK); CHECK(font_glyph_ref_put(NULL), BAD_ARG); CHECK(font_glyph_ref_put(glyph), OK); CHECK(font_glyph_ref_put(glyph), OK); b = true; for(i = 0; b && i < w*h*Bpp; ++i) b = ((int)buffer[i] == 0); CHECK(b, false); for(i = 32; i < 127; ++i) { size_t required_buffer_size = 0; CHECK(font_rsrc_get_glyph(font, (wchar_t)i, &glyph), OK); CHECK(font_glyph_get_bitmap(glyph, true, &w, &h, &Bpp, NULL), OK); required_buffer_size = (size_t)(w * h * Bpp) * sizeof(unsigned char); if(required_buffer_size > buffer_size) { buffer = MEM_REALLOC(&mem_default_allocator,buffer, required_buffer_size); NCHECK(buffer, NULL); buffer_size = required_buffer_size; } CHECK(font_glyph_get_bitmap(glyph, true, &w, &h, &Bpp, buffer), OK); NCHECK(snprintf(buf, BUFSIZ, "/tmp/%.3d.ppm", i - 32), BUFSIZ); CHECK(image_ppm_write(buf, w, h, Bpp, buffer), 0); CHECK(font_glyph_ref_put(glyph), OK); } MEM_FREE(&mem_default_allocator, buffer); CHECK(font_rsrc_ref_get(NULL), BAD_ARG); CHECK(font_rsrc_ref_get(font), OK); CHECK(font_rsrc_ref_put(NULL), BAD_ARG); CHECK(font_rsrc_ref_put(font), OK); CHECK(font_rsrc_ref_put(font), OK); CHECK(font_system_ref_get(NULL), BAD_ARG); CHECK(font_system_ref_get(sys), OK); CHECK(font_system_ref_put(NULL), BAD_ARG); CHECK(font_system_ref_put(sys), OK); CHECK(font_system_ref_put(sys), OK); CHECK(MEM_ALLOCATED_SIZE(&mem_default_allocator), 0); return 0; error: return -1; }