/* test-props.c Edouard.Thiel@lif.univ-mrs.fr - 04/03/2007 Test the text properties in src/props.c USAGE: ./test-props */ #include void test_props () { Npic_props props; printf ("-------- Test props --------\n"); NpicInitProps (&props); printf ("Inserting props ...\n"); NpicAddProp (&props, "Width", "5cm"); NpicAddProp (&props, "Height", "7cm"); NpicAddProp (&props, "Weight", "28g"); NpicAddProp (&props, "Cost", "3EUR"); NpicAddProp (&props, "Colour", "Blue"); NpicPrintProps (&props); printf ("Getting props ...\n"); printf ("Width: %s\n", NpicGetProp (&props, "Width")); printf ("Height: %s\n", NpicGetProp (&props, "Height")); printf ("Weight: %s\n", NpicGetProp (&props, "Weight")); printf ("Cost: %s\n", NpicGetProp (&props, "Cost")); printf ("Colour: %s\n", NpicGetProp (&props, "Colour")); printf ("Suppressing props ...\n"); NpicSupprProp (&props, "Width"); NpicSupprProp (&props, "Weight"); NpicPrintProps (&props); printf ("Getting props ...\n"); printf ("Width: %s\n", NpicGetProp (&props, "Width")); printf ("Height: %s\n", NpicGetProp (&props, "Height")); printf ("Weight: %s\n", NpicGetProp (&props, "Weight")); printf ("Cost: %s\n", NpicGetProp (&props, "Cost")); printf ("Colour: %s\n", NpicGetProp (&props, "Colour")); printf ("Trying errors ...\n"); NpicSupprProp (&props, "Width"); NpicAddProp (&props, "", "Empty"); NpicAddProp (&props, "With space", ""); NpicAddProp (&props, "With :", ""); NpicAddProp (&props, "With ", ""); NpicAddProp (&props, "With\n", ""); NpicAddProp (&props, "With-é", ""); NpicAddProp (&props, "Val-empty", ""); NpicAddProp (&props, "Val-with-space", "one two"); NpicAddProp (&props, "Val-with-tab", "one two"); NpicAddProp (&props, "Val-with-colon", "one:two"); NpicAddProp (&props, "Val-with-rc", "one\ntwo"); NpicAddProp (&props, "Val-with-eacute", "oneétwo"); printf ("Changing a prop ...\n"); NpicAddProp (&props, "Cost", "71EUR"); NpicPrintProps (&props); printf ("Testing if a prop is set ...\n"); printf ("Width: %s\n", NpicHasProp (&props, "Width") ? "set" : "not set"); printf ("Height: %s\n", NpicHasProp (&props, "Height") ? "set" : "not set"); printf ("Weight: %s\n", NpicHasProp (&props, "Weight") ? "set" : "not set"); printf ("Cost: %s\n", NpicHasProp (&props, "Cost") ? "set" : "not set"); printf ("Colour: %s\n", NpicHasProp (&props, "Colour") ? "set" : "not set"); NpicFreeProps (&props); } void test_image () { Npic_image *np; printf ("-------- Test image --------\n"); np = NpicCreateImage_2c (10, 20, 0, 0); printf ("Inserting props ...\n"); NpicImageAddProp (np, "Width", "5cm"); NpicImageAddProp (np, "Height", "7cm"); NpicImageAddProp (np, "Weight", "28g"); NpicImageAddProp (np, "Cost", "3EUR"); NpicImageAddProp (np, "Colour", "Blue"); NpicImagePrintProps (np); printf ("Getting props ...\n"); printf ("Width: %s\n", NpicImageGetProp (np, "Width")); printf ("Height: %s\n", NpicImageGetProp (np, "Height")); printf ("Weight: %s\n", NpicImageGetProp (np, "Weight")); printf ("Cost: %s\n", NpicImageGetProp (np, "Cost")); printf ("Colour: %s\n", NpicImageGetProp (np, "Colour")); printf ("Suppressing props ...\n"); NpicImageSupprProp (np, "Width"); NpicImageSupprProp (np, "Weight"); NpicImagePrintProps (np); printf ("Getting props ...\n"); printf ("Width: %s\n", NpicImageGetProp (np, "Width")); printf ("Height: %s\n", NpicImageGetProp (np, "Height")); printf ("Weight: %s\n", NpicImageGetProp (np, "Weight")); printf ("Cost: %s\n", NpicImageGetProp (np, "Cost")); printf ("Colour: %s\n", NpicImageGetProp (np, "Colour")); printf ("Trying errors ...\n"); NpicImageSupprProp (np, "Width"); NpicImageAddProp (np, "", "Nothing"); printf ("Changing a prop ...\n"); NpicImageAddProp (np, "Cost", "71EUR"); NpicImagePrintProps (np); printf ("Testing if a prop is set ...\n"); printf ("Width: %s\n", NpicImageHasProp (np, "Width") ? "set" : "not set"); printf ("Height: %s\n", NpicImageHasProp (np, "Height") ? "set" : "not set"); printf ("Weight: %s\n", NpicImageHasProp (np, "Weight") ? "set" : "not set"); printf ("Cost: %s\n", NpicImageHasProp (np, "Cost") ? "set" : "not set"); printf ("Colour: %s\n", NpicImageHasProp (np, "Colour") ? "set" : "not set"); NpicDestroyImage (np); } void test_mask () { Npic_mask *m; printf ("-------- Test mask --------\n"); m = NpicCreateMask (NPIC_MASK_2L); printf ("Inserting props ...\n"); NpicMaskAddProp (m, "Width", "5cm"); NpicMaskAddProp (m, "Height", "7cm"); NpicMaskAddProp (m, "Weight", "28g"); NpicMaskAddProp (m, "Cost", "3EUR"); NpicMaskAddProp (m, "Colour", "Blue"); NpicMaskPrintProps (m); printf ("Getting props ...\n"); printf ("Width: %s\n", NpicMaskGetProp (m, "Width")); printf ("Height: %s\n", NpicMaskGetProp (m, "Height")); printf ("Weight: %s\n", NpicMaskGetProp (m, "Weight")); printf ("Cost: %s\n", NpicMaskGetProp (m, "Cost")); printf ("Colour: %s\n", NpicMaskGetProp (m, "Colour")); printf ("Suppressing props ...\n"); NpicMaskSupprProp (m, "Width"); NpicMaskSupprProp (m, "Weight"); NpicMaskPrintProps (m); printf ("Getting props ...\n"); printf ("Width: %s\n", NpicMaskGetProp (m, "Width")); printf ("Height: %s\n", NpicMaskGetProp (m, "Height")); printf ("Weight: %s\n", NpicMaskGetProp (m, "Weight")); printf ("Cost: %s\n", NpicMaskGetProp (m, "Cost")); printf ("Colour: %s\n", NpicMaskGetProp (m, "Colour")); printf ("Trying errors ...\n"); NpicMaskSupprProp (m, "Width"); NpicMaskAddProp (m, "", "Nothing"); printf ("Changing a prop ...\n"); NpicMaskAddProp (m, "Cost", "71EUR"); NpicMaskPrintProps (m); printf ("Testing if a prop is set ...\n"); printf ("Width: %s\n", NpicMaskHasProp (m, "Width") ? "set" : "not set"); printf ("Height: %s\n", NpicMaskHasProp (m, "Height") ? "set" : "not set"); printf ("Weight: %s\n", NpicMaskHasProp (m, "Weight") ? "set" : "not set"); printf ("Cost: %s\n", NpicMaskHasProp (m, "Cost") ? "set" : "not set"); printf ("Colour: %s\n", NpicMaskHasProp (m, "Colour") ? "set" : "not set"); NpicDestroyMask (m); } int main (int argc, char *argv[]) { int i; if (argc < 2) { printf ("Usage: %s [-props -image -mask] \n", argv[0]); exit(1); } for (i = 1; i < argc; i++) { if (strcmp (argv[i], "-props") == 0) test_props(); else if (strcmp (argv[i], "-image") == 0) test_image(); else if (strcmp (argv[i], "-mask") == 0) test_mask(); } exit (0); }