Split errstrings.h from error.h to avoid texts becoming included in several object...
[AROS.git] / workbench / demos / rtdemo.c
blob61ec704ea24b155657c25c9cce4fc533573ea202
1 /*
2 Copyright © 1997, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Show the use or Ressource Tracking (RT)
6 Lang: english
7 */
8 #define ENABLE_RT 1 /* Enable RT */
10 #include <stdio.h>
12 #include <exec/memory.h>
13 #include <intuition/intuition.h>
15 #include <proto/exec.h>
16 #include <proto/dos.h>
17 #include <proto/intuition.h>
19 #include <aros/rt.h>
21 struct IntuitionBase * IntuitionBase;
23 int main (int argc, char ** argv)
25 APTR mem, illmem;
26 BPTR file;
27 int size;
30 Init resource tracking. This will be a NOP if ENABLE_RT is 0 or
31 undefined.
33 RT_Init();
35 /* 1. Allocate some memory */
36 printf ("Allocating %d bytes of memory\n", size=60);
38 mem = AllocMem (size, MEMF_ANY);
40 /* Bug 1: Ooops... forgetting about mem */
41 printf ("Bug 1: Forgetting about %d bytes at %p\n", size, mem);
42 mem = AllocMem (size, MEMF_ANY);
44 printf ("Got some %d bytes at %p\n", size, mem);
47 Bug 2: Wrong size. Take note that RT will *not* free the memory.
48 This will take place when RT_Exit() is called.
50 printf ("Bug 2: Freeing %d bytes at %p\n", size+10, mem);
52 FreeMem (mem, size+10);
54 /* Bug 3: Wrong pointer */
55 illmem = (APTR)4;
56 printf ("Bug 3: Freeing %d bytes at %p\n", size, illmem);
58 FreeMem (illmem, size);
60 /* Allocate some more memory */
61 mem = AllocVec (size, MEMF_ANY);
62 printf ("Bug 4: Forget to free %d bytes at %p\n", size, mem);
64 /* Bug 5: Wrong pointer */
65 illmem = (APTR)4;
66 printf ("Bug 5: Freeing %p\n", illmem);
68 FreeVec (illmem);
70 /* This is valid */
71 FreeVec (NULL);
73 mem = IntuitionBase = (struct IntuitionBase *) OpenLibrary (INTUITIONNAME, 0);
75 printf ("Bug 12: Open a window and forget about it\n");
76 OpenWindowTags (NULL, TAG_END);
78 printf ("Bug 6: OverWriting IntuitionBase (%p)\n", IntuitionBase);
79 IntuitionBase = (struct IntuitionBase *)23;
81 CloseLibrary ((struct Library *) IntuitionBase);
83 IntuitionBase = mem;
85 /* Funny things with files */
86 printf ("Bug 7: Open a file with an illegal mode\n");
87 file = Open ("test", 0xbad);
89 printf ("Bug 8: Open a file with an illegal name\n");
90 file = Open (NULL, MODE_NEWFILE);
92 printf ("Bug 9: Open a file which doesn't exist and forget to check\n");
93 file = Open ("XG&hg", MODE_OLDFILE);
95 Read (file, mem, size);
97 printf ("Bug 10: Write with an illegal buffer\n");
98 file = Open ("test.rtdemo", MODE_NEWFILE);
100 Write (file, NULL, size);
102 printf ("Bug 11: Close the wrong file\n");
103 file = (BPTR)mem;
104 Close (file);
106 DeleteFile ("test.rtdemo");
109 Terminate RT. This will also be a NOP if RT is not enabled. If
110 any resources are still allocated, then this will free and print
111 them.
113 printf ("Show Bugs 1, 2, 6, 11 and 12\n");
114 RT_Exit ();
116 return 0;