Пример #1
0
char *test_print()
{
    object = Object_new();
    Object_print(object);
    Object_destroy(object);

    object = True_new();
    Object_print(object);
    Object_destroy_immortal(object);

    object = False_new();
    Object_print(object);
    Object_destroy_immortal(object);

    object = Nil_new();
    Object_print(object);
    Object_destroy_immortal(object);

    object = Integer_new(123);
    Object_print(object);
    Object_destroy(object);

    bstring hello = bfromcstr("hello");
    object = String_new(hello);
    Object_print(object);
    Object_destroy(object);

    return NULL;
}
Пример #2
0
Cursor
prima_null_pointer( void)
{
	if ( guts. null_pointer == nilHandle) {
		Handle nullc = ( Handle) create_object( "Prima::Icon", "", nil);
		PIcon  n = ( PIcon) nullc;
		Pixmap xor, and;
		XColor xc;
		if ( nullc == nilHandle) {
			warn("Error creating icon object");
			return nilHandle;
		}
		n-> self-> create_empty( nullc, 16, 16, imBW);
		memset( n-> mask, 0xFF, n-> maskSize);
		if ( !prima_create_icon_pixmaps( nullc, &xor, &and)) {
			warn( "Error creating null cursor pixmaps");
			Object_destroy( nullc);
			return nilHandle;
		}
		Object_destroy( nullc);
		xc. red = xc. green = xc. blue = 0;
		xc. pixel = guts. monochromeMap[0];
		xc. flags = DoRed | DoGreen | DoBlue;
		guts. null_pointer = XCreatePixmapCursor( DISP, xor, and, &xc, &xc, 0, 0);
		XCHECKPOINT;
		XFreePixmap( DISP, xor);
		XFreePixmap( DISP, and);
		if ( !guts. null_pointer) {
			warn( "Error creating null cursor from pixmaps");
			return nilHandle;
		}
	}
	return guts. null_pointer;
}
Пример #3
0
HICON
image_make_icon_handle( Handle img, Point size, Point * hotSpot)
{
   PIcon i = ( PIcon) img;
   HICON    r;
   ICONINFO ii;
   int    bpp = i-> type & imBPP;
   Bool  noSZ   = i-> w != size. x || i-> h != size. y;
   Bool  noBPP  = bpp != 1 && bpp != 4 && bpp != 8 && bpp != 24;
   HDC dc;
   XBITMAPINFO bi;
   Bool notAnIcon = !kind_of( img, CIcon);

   ii. fIcon = hotSpot ? false : true;
   ii. xHotspot = hotSpot ? hotSpot-> x : 0;
   ii. yHotspot = hotSpot ? hotSpot-> y : 0;

   if ( noSZ || noBPP) {
      i = ( PIcon)( i-> self-> dup( img));

      if ( noSZ)
         i-> self-> set_size(( Handle) i, size);
      if ( noBPP)
         i-> self-> set_type(( Handle) i,
             ( bpp < 4) ? 1 :
             (( bpp < 8) ? 4 :
             (( bpp < 24) ? 8 : 24))
      );
   }

   if (!( dc = dc_alloc())) {
      if (( Handle) i != img) Object_destroy(( Handle) i);
      return NULL;
   }
   image_get_binfo(( Handle)i, &bi);
   if ( bi. bmiHeader. biClrUsed > 0)
      bi. bmiHeader. biClrUsed = bi. bmiHeader. biClrImportant = i-> palSize;

   if ( !( ii. hbmColor = CreateDIBitmap( dc, &bi. bmiHeader, CBM_INIT,
       i-> data, ( BITMAPINFO*) &bi, DIB_RGB_COLORS))) apiErr;
   bi. bmiHeader. biBitCount = bi. bmiHeader. biPlanes = 1;
   bi. bmiColors[ 0]. rgbRed = bi. bmiColors[ 0]. rgbGreen = bi. bmiColors[ 0]. rgbBlue = 0;
   bi. bmiColors[ 1]. rgbRed = bi. bmiColors[ 1]. rgbGreen = bi. bmiColors[ 1]. rgbBlue = 255;

   if ( !( ii. hbmMask  = CreateDIBitmap( dc, &bi. bmiHeader, CBM_INIT,
      notAnIcon ? NULL : i-> mask, ( BITMAPINFO*) &bi, DIB_RGB_COLORS))) apiErr;
   
   dc_free();

   if ( !( r = CreateIconIndirect( &ii))) apiErr;

   DeleteObject( ii. hbmColor);
   DeleteObject( ii. hbmMask);
   if (( Handle) i != img) Object_destroy(( Handle) i);
   return r;
}
Пример #4
0
void teardown_method()
{
  Object_destroy(self);
  free(literals);

  free(instructions);

  Object_destroy(locals[0]);
  free(locals);
}
Пример #5
0
char *test_destroy()
{
    Object_destroy(object);
    Object_destroy(parent);

    Object_destroy(immortal);
    mu_assert(immortal->immortal == 1, "Immortal object was destroyed.");

    // Cleanup immortal object manually
    Object_destroy_immortal(immortal);
    return NULL;
}
Пример #6
0
Bool
apc_image_begin_paint( Handle self)
{
   apcErrClear;
   objCheck false;
   if ( !( sys ps = CreateCompatibleDC( 0))) apiErrRet;
   if ( sys bm == nil) {
      Handle deja  = image_enscreen( self, self);
      if ( !image_set_cache( deja, self)) {
         DeleteDC( sys ps);
	 sys ps = nil;
	 return false;
      }
      if ( deja != self) Object_destroy( deja);
   }
   sys stockBM = SelectObject( sys ps, sys bm);
   if ( !sys pal)
      sys pal = image_make_bitmap_palette( self);
   hwnd_enter_paint( self);
   if (( PImage( self)-> type & imBPP) == imbpp1) sys bpp = 1;
   if ( sys pal) {
      SelectPalette( sys ps, sys pal, 0);
      RealizePalette( sys ps);
   }
   return true;
}
Пример #7
0
Handle
Widget_shape( Handle self, Bool set, Handle mask)
{
    if ( var-> stage > csFrozen) return nilHandle;

    if ( !set) {
        if ( apc_widget_get_shape( self, nilHandle)) {
            HV * profile = newHV();
            Handle i = Object_create( "Prima::Image", profile);
            sv_free(( SV *) profile);
            apc_widget_get_shape( self, i);
            --SvREFCNT( SvRV((( PAnyObject) i)-> mate));
            return i;
        } else
            return nilHandle;
    }

    if ( mask && !kind_of( mask, CImage)) {
        warn("RTC008A: Illegal object reference passed to Widget::shape");
        return nilHandle;
    }

    if ( mask && (( PImage( mask)-> type & imBPP) != imbpp1)) {
        Handle i = CImage( mask)-> dup( mask);
        ++SvREFCNT( SvRV( PImage( i)-> mate));
        CImage( i)-> set_conversion( i, ictNone);
        CImage( i)-> set_type( i, imBW);
        apc_widget_set_shape( self, i);
        --SvREFCNT( SvRV( PImage( i)-> mate));
        Object_destroy( i);
    } else
        apc_widget_set_shape( self, mask);

    return nilHandle;
}
Пример #8
0
void SimulateState_destroy(SimulateState_ptr self)
{
  SIMULATE_STATE_CHECK_INSTANCE(self);
  check_integrity(self);

  Object_destroy(OBJECT(self), NULL); self = SIMULATE_STATE(NULL);
}
Пример #9
0
static SV *
image_server( Handle self, PClipboardFormatReg instance, int function, SV * data)
{
	ClipboardDataRec c;
	switch( function) {
	case cefInit:
		return ( SV *) cfBitmap;
	case cefFetch:
		{
			HV * profile = newHV();
			c. image = Object_create( "Prima::Image", profile);
			sv_free(( SV *) profile);
			if ( apc_clipboard_get_data( self, cfBitmap, &c)) {
				--SvREFCNT( SvRV( PImage(c. image)-> mate));
				return newSVsv( PImage(c. image)->  mate);
			}
			Object_destroy( c. image);
		}
		break;
	case cefStore:
		c. image = gimme_the_mate( data);

		if ( !kind_of( c. image, CImage)) {
			warn("Not an image passed to clipboard");
			return nilSV;
		}
		instance-> success = apc_clipboard_set_data( self, cfBitmap, &c);
		instance-> written = true;
		break;
	}
	return nilSV;
}
Пример #10
0
char *test_loadslot()
{
  instructions[0] = Instruction_new(OP_LOADSELF(0));
  instructions[1] = Instruction_new(OP_LOADS(1, 3));
  instructions[2] = Instruction_new(OP_LOADSLOT(2, 0, 1));
  instructions[3] = Instruction_new(OP_RET(2));

  bstring slotname = bfromcstr("price");

  Object *value = Integer_new(literals[0]);

  Object_register_slot(self, slotname, value);

  machine = MACHINE(4);
  Object *result = Machine_run(machine, self);

  mu_assert(value == result, "LOADSLOT failed.");

  Machine_destroy(machine);

  Object_delete_slot(self, slotname);

  bdestroy(slotname);

  Object_destroy(value);

  Instruction_destroy(instructions[0]);
  Instruction_destroy(instructions[1]);
  Instruction_destroy(instructions[2]);
  Instruction_destroy(instructions[3]);
  return NULL;
}
Пример #11
0
char *test_slots()
{
    Object *parent_age   = Integer_new(50);
    Object *parent_money = Integer_new(1000);
    Object *child_age    = Integer_new(25);

    Object *parent = Object_new();
    Object *child  = Object_new_with_parent(parent);

    bstring money = bfromcstr("money");
    bstring age   = bfromcstr("age");

    Object_register_slot(parent, bfromcstr("money"), parent_money);
    Object_register_slot(parent, bfromcstr("age"), parent_age);
    Object_register_slot(child, bfromcstr("age"), child_age);

    mu_assert(Object_lookup_slot(parent, age)->value.integer == 50, "Parent age is wrong");
    mu_assert(Object_lookup_slot(child, age)->value.integer == 25, "Child age is wrong");
    mu_assert(Object_lookup_slot(parent, money)->value.integer == 1000, "Parent money is wrong");
    mu_assert(Object_lookup_slot(child, money)->value.integer == 1000, "Child money is wrong");

    Object_destroy(child);

    bdestroy(money);
    bdestroy(age);
    return NULL;
}
Пример #12
0
char *test_integers()
{
    object = Integer_new(123);
    mu_assert(object->type == tInteger, "Integer has the wrong type");
    mu_assert(object->value.integer == 123, "Integer value wasn't set correctly");

    Object_destroy(object);
    return NULL;
}
Пример #13
0
char *test_strings()
{
    bstring bstr = bfromcstr("123");
    object = String_new(bstr);
    mu_assert(object->type == tString, "String has the wrong type");
    mu_assert(bstrcmp(object->value.string, bstr) == 0, "String value wasn't set correctly");

    Object_destroy(object);
    return NULL;
}
Пример #14
0
char *test_hashes()
{
    Object **contents = calloc(4, sizeof(Object*));
    contents[0] = String_new(bfromcstr("foo"));
    contents[1] = Integer_new(1);
    contents[2] = String_new(bfromcstr("bar"));
    contents[3] = Integer_new(2);

    Object *array = Array_new(contents, 4);
    Object *object = Hash_new(array);

    mu_assert(object->type == tHash, "Hash has the wrong type");
    Hashmap *map = (Hashmap*)object->value.other;
    Object *foo = (Object*)Hashmap_get(map, contents[0]);
    mu_assert(foo->value.integer == 1, "Hash element 'foo' is wrong.");
    Object *bar = (Object*)Hashmap_get(map, contents[2]);
    mu_assert(bar->value.integer == 2, "Hash element 'bar' is wrong.");

    Object_destroy(object);
    Object_destroy(array);
    free(contents);
    return NULL;
}
Пример #15
0
Bool
apc_application_go( Handle self)
{
	if (!application) return false;

	XNoOp( DISP);
	XFlush( DISP);

	while ( prima_one_loop_round( WAIT_ALWAYS, true))
		;

	if ( application) Object_destroy( application);
	application = nilHandle;
	return true;
}
Пример #16
0
void
Application_cleanup( Handle self)
{
   int i;

   for ( i = 0; i < var-> widgets. count; i++)
      Object_destroy( var-> widgets. items[i]);
      
   if ( var-> icon)
      my-> detach( self, var-> icon, true);
   var-> icon = nilHandle;

   my-> first_that_component( self, (void*)kill_all, nil);

   CDrawable-> cleanup( self);
}
Пример #17
0
char *test_loadi()
{
  instructions[0] = Instruction_new(OP_LOADI(0, 0));
  instructions[1] = Instruction_new(OP_RET(0));

  machine = MACHINE(2);

  Object *result = Machine_run(machine, self);

  mu_assert(result->value.integer == 123, "MOVE or LOADI failed.");

  Machine_destroy(machine);
  Object_destroy(result);

  DESTROY_INSTRUCTIONS();
  return NULL;
}
Пример #18
0
char *test_setlocal()
{
  instructions[0] = Instruction_new(OP_LOADI(0, 0));
  instructions[1] = Instruction_new(OP_SETLOCAL(0, 1));
  instructions[2] = Instruction_new(OP_RET(0));

  machine = MACHINE(3);
  Object *result = Machine_run(machine, self);

  mu_assert(locals[1]->value.integer == 123, "SETLOCAL failed.");

  Machine_destroy(machine);

  Object_destroy(result);
  Instruction_destroy(instructions[0]);
  Instruction_destroy(instructions[1]);
  Instruction_destroy(instructions[2]);
  return NULL;
}
Пример #19
0
char *test_arrays()
{
    Object **contents = calloc(4, sizeof(Object*));
    contents[0] = Integer_new(0);
    contents[1] = Integer_new(1);
    contents[2] = Integer_new(2);
    contents[3] = Integer_new(3);

    Object *object = Array_new(contents, 4);

    mu_assert(object->type == tArray, "Array has the wrong type");
    DArray *array = (DArray*)object->value.other;
    Object *first = (Object*)DArray_at(array, 0);
    mu_assert(first->value.integer == 0, "Array element is wrong.");

    Object_destroy(object);
    free(contents);
    return NULL;
}
Пример #20
0
char *test_loads()
{
  instructions[0] = Instruction_new(OP_LOADS(0, 1));
  instructions[1] = Instruction_new(OP_RET(0));

  bstring literal = bfromcstr("print");

  machine = MACHINE(2);

  Object *result = Machine_run(machine, self);

  mu_assert(bstrcmp(result->value.string, literal) == 0, "LOADS failed.");

  Machine_destroy(machine);
  Object_destroy(result);
  bdestroy(literal);

  DESTROY_INSTRUCTIONS();
  return NULL;
}
Пример #21
0
char *test_jmp()
{
  instructions[0] = Instruction_new(OP_LOADI(0, 0));
  instructions[1] = Instruction_new(OP_JMP(2));
  instructions[2] = Instruction_new(OP_LOADS(0, 1));
  instructions[3] = Instruction_new(OP_RET(0));

  machine = MACHINE(4);

  Object *result = Machine_run(machine, self);

  mu_assert(result->type == tInteger, "JMP failed.");
  mu_assert(result->value.integer == 123, "JMP failed.");

  Machine_destroy(machine);

  Object_destroy(result);
  DESTROY_INSTRUCTIONS();
  return NULL;
}
Пример #22
0
char *test_makearray()
{
  instructions[0] = Instruction_new(OP_LOADSELF(1));
  instructions[1] = Instruction_new(OP_LOADS(2, 1));
  instructions[2] = Instruction_new(OP_LOADI(3, 0));
  instructions[3] = Instruction_new(OP_MAKEARRAY(0, 1, 3));
  instructions[4] = Instruction_new(OP_RET(0));

  machine = MACHINE(5);
  Object *result = Machine_run(machine, self);
  DArray *array = (DArray*)result->value.other;

  mu_assert(DArray_count(array) == 3, "Array has not a length of 3.");

  Object *e_self = (Object*)DArray_at(array, 0);
  Object *e_str  = (Object*)DArray_at(array, 1);
  Object *e_int  = (Object*)DArray_at(array, 2);

  printf("Refcount for self: %i\n", e_self->refcount);
  printf("Refcount for str: %i\n", e_str->refcount);
  printf("Refcount for int: %i\n", e_int->refcount);

  bstring print = bfromcstr("print");

  mu_assert(result->type == tArray, "Array type is not array.");
  mu_assert(e_self == self, "First array element is not self.");
  mu_assert(bstrcmp(e_str->value.string, print) == 0, "Second array element is not 'print'.");
  mu_assert(e_int->value.integer == 123, "Third array element is not 123.");

  Machine_destroy(machine);
  Object_destroy(result);

  bdestroy(print);

  Instruction_destroy(instructions[0]);
  Instruction_destroy(instructions[1]);
  Instruction_destroy(instructions[2]);
  Instruction_destroy(instructions[3]);
  Instruction_destroy(instructions[4]);
  return NULL;
}
Пример #23
0
char *test_send()
{
  instructions[0] = Instruction_new(OP_LOADI(0, 0));
  instructions[1] = Instruction_new(OP_LOADS(1, 2));
  instructions[2] = Instruction_new(OP_LOADI(2, 0));
  instructions[3] = Instruction_new(OP_SEND(0, 1, 2));
  instructions[4] = Instruction_new(OP_RET(0));

  machine = MACHINE(5);
  Object *result = Machine_run(machine, self);

  mu_assert(result->value.integer == 246, "SEND failed.");

  Machine_destroy(machine);
  Object_destroy(result);

  Instruction_destroy(instructions[0]);
  Instruction_destroy(instructions[1]);
  Instruction_destroy(instructions[2]);
  Instruction_destroy(instructions[3]);
  Instruction_destroy(instructions[4]);
  return NULL;
}
Пример #24
0
void
Object_destroy(Object *object)
{
  switch(object->type) {
    case tString:
      bdestroy(object->value.as_string);
      break;
    case tArray: {
      DArray *ary = object->value.as_array;
      Object *obj = NULL;
      while((obj = (Object*)DArray_pop(ary)) != NULL) {
        Object_destroy(obj);
      }
      break;
    }
    case tHash: {
      Hashmap_destroy(object->value.as_hash);
    }
    default:
      break;
  }

  free(object);
}
Пример #25
0
void PrinterNonAmbiguousDot_destroy(PrinterNonAmbiguousDot_ptr self)
{
  PRINTER_ANON_MAP_ENTRY_CHECK_INSTANCE(self);

  Object_destroy(OBJECT(self), NULL);
}
Пример #26
0
static Bool
create_cursor(Handle self, Handle icon, Point hot_spot)
{
#ifdef HAVE_X11_XCURSOR_XCURSOR_H
	DEFXX;
	XcursorImage* i;
	PIcon c = PIcon(icon);
	Bool kill;
	int x, y;
	XcursorPixel * dst;
	Byte * src_data, * src_mask;

	if ( hot_spot. x < 0) hot_spot. x = 0;
	if ( hot_spot. y < 0) hot_spot. y = 0;
	if ( hot_spot. x >= c-> w) hot_spot. x = c-> w - 1;
	if ( hot_spot. y >= c-> h) hot_spot. y = c-> h - 1;
	XX-> pointer_hot_spot = hot_spot;
	if (( i = XcursorImageCreate( c-> w, c-> h )) == NULL) {
		warn( "XcursorImageCreate(%d,%d) error", c->w, c->h);
		return false;
	}
	i-> xhot = hot_spot. x;
	i-> yhot = c-> h - hot_spot. y - 1;

	if ( c-> type != imRGB || c-> maskType != imbpp8 ) {
		icon = CIcon(icon)->dup(icon);
		kill = true;
		CIcon(icon)-> set_type( icon, imRGB );
		CIcon(icon)-> set_maskType( icon, imbpp8 );
	} else
		kill = false;
	c = PIcon(icon);
	src_data = c->data + c->lineSize * ( c-> h - 1 );
	src_mask = c->mask + c->maskLine * ( c-> h - 1 );
	dst = i->pixels;
	for ( y = 0; y < c-> h; y++) {
		Byte * s_data = src_data, * s_mask = src_mask;
		for ( x = 0; x < c-> w; x++) {
			*(dst++) =
				s_data[0]|
				(s_data[1] << 8)|
				(s_data[2] << 16)|
				(*(s_mask++) << 24)
				;
			s_data += 3;
		}
		src_mask -= c->maskLine;
		src_data -= c->lineSize;
	}
	if ( kill ) Object_destroy(icon);

	XX-> user_pointer = XcursorImageLoadCursor(DISP, i);
	if ( XX-> user_pointer == None) {
		XcursorImageDestroy(i);
		warn( "error creating cursor");
		return false;
	}
	XX-> user_xcursor = i;

	return true;

#else

	DEFXX;
	Handle cursor;
	Bool noSZ  = PIcon(icon)-> w != guts.cursor_width || PIcon(icon)-> h != guts.cursor_height;
	Bool noBPP = (PIcon(icon)-> type & imBPP) != 1;
	XColor xcb, xcw;
	PIcon c;

	if ( noSZ || noBPP) {
		cursor = CIcon(icon)->dup(icon);
		c = PIcon(cursor);
		if ( cursor == nilHandle) {
			warn( "Error duping user cursor");
			return false;
		}
		if ( noSZ) {
			CIcon(cursor)-> stretch( cursor, guts.cursor_width, guts.cursor_height);
			if ( c-> w != guts.cursor_width || c-> h != guts.cursor_height) {
				warn( "Error stretching user cursor");
				Object_destroy( cursor);
				return false;
			}
		}
		if ( noBPP) {
			CIcon(cursor)-> set_type( cursor, imMono);
			if ((c-> type & imBPP) != 1) {
				warn( "Error black-n-whiting user cursor");
				Object_destroy( cursor);
				return false;
			}
		}
	} else
		cursor = icon;
	if ( !prima_create_icon_pixmaps( cursor, &XX-> user_p_source, &XX-> user_p_mask)) {
		warn( "Error creating user cursor pixmaps");
		if ( noSZ || noBPP)
			Object_destroy( cursor);
		return false;
	}
	if ( noSZ || noBPP)
		Object_destroy( cursor);
	if ( hot_spot. x < 0) hot_spot. x = 0;
	if ( hot_spot. y < 0) hot_spot. y = 0;
	if ( hot_spot. x >= guts. cursor_width)  hot_spot. x = guts. cursor_width  - 1;
	if ( hot_spot. y >= guts. cursor_height) hot_spot. y = guts. cursor_height - 1;
	XX-> pointer_hot_spot = hot_spot;
	xcb. red = xcb. green = xcb. blue = 0;
	xcw. red = xcw. green = xcw. blue = 0xFFFF;
	xcb. pixel = guts. monochromeMap[0];
	xcw. pixel = guts. monochromeMap[1];
	xcb. flags = xcw. flags = DoRed | DoGreen | DoBlue;
	XX-> user_pointer = XCreatePixmapCursor( DISP, XX-> user_p_source,
		XX-> user_p_mask, &xcw, &xcb,
		hot_spot. x, guts.cursor_height - hot_spot. y - 1);
	if ( XX-> user_pointer == None) {
		warn( "error creating cursor from pixmaps");
		return false;
	}
	return true;
#endif
}
Пример #27
0
void HrcDumper_destroy(HrcDumper_ptr self)
{
  HRC_DUMPER_CHECK_INSTANCE(self);

  Object_destroy(OBJECT(self), NULL);
}
Пример #28
0
/**Function********************************************************************

  Synopsis           [The BDDPartialTraceExecutor class destructor]

  Description        [The BDDPartialTraceExecutor class destructor]

  SideEffects        []

  SeeAlso            [BDDPartialTraceExecutor_create]

******************************************************************************/
void BDDPartialTraceExecutor_destroy(BDDPartialTraceExecutor_ptr self)
{
  BDD_PARTIAL_TRACE_EXECUTOR_CHECK_INSTANCE(self);

  Object_destroy(OBJECT(self), NULL);
}
Пример #29
0
/**Function********************************************************************

  Synopsis           [The BoolEncClient class destructor]

  Description [The BoolEncClient class destructor. Since this class is
  pure, only a virtual destructor is provided, and there is no
  constructor]

  SideEffects        []

  SeeAlso            []   
  
******************************************************************************/
void BoolEncClient_destroy(BoolEncClient_ptr self)
{
  BOOL_ENC_CLIENT_CHECK_INSTANCE(self);

  Object_destroy(OBJECT(self), NULL);
}