Release 970305
[wine] / ipc / dde_atom_test.c
1 /***************************************************************************
2  * Copyright 1995, Technion, Israel Institute of Technology
3  * Electrical Eng, Software Lab.
4  * Author:    Michael Veksler.
5  ***************************************************************************
6  * File:      dde_atom_test.c
7  * Purpose :  tests for dde_atom object
8  ***************************************************************************
9  */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <win.h>
13 #include "dde_atom.h"
14 #include "shm_main_blk.h"
15 #include <stddebug.h>
16 #include <debug.h>
17 #define TOGETHER (DDE_ATOMS/5)
18
19
20 /* run random sequences */
21 int main()
22 {
23   ATOM atom_list[TOGETHER];
24   char str[TOGETHER][80];
25   int i,j,atom_n;
26   int atom_len[TOGETHER];
27   
28   debugging_shm=1;
29   debugging_atom=0;
30   debugging_sem=0;
31   
32   for (i=0 ; i<=10000/TOGETHER ; i++) {
33      for (atom_n=0 ; atom_n<TOGETHER ; atom_n++) {
34         atom_len[atom_n]=rand()%64+1;
35         for (j=atom_len[atom_n]-1; j>=0; j--) 
36            do {
37               str[atom_n][j]=(char)(rand()%255+1);
38            } while (j==0 && str[atom_n][j]=='#');
39
40         str[atom_n][ atom_len[atom_n] ]='\0';
41
42         atom_list[atom_n]=GlobalAddAtom(str[atom_n]);
43
44         if (atom_list[atom_n]==0) {
45            fprintf(stderr,"failed i=%d, atom_n=%d\n",i,atom_n);
46            return 1;
47         }
48         if (atom_list[atom_n]!=GlobalAddAtom(str[atom_n])) {
49            fprintf(stderr,
50                    "wrong second GlobalAddAtom(\"%s\")\n", str[atom_n]);
51            return 1;
52         }
53      } /* for */
54      for (atom_n=0 ; atom_n<TOGETHER ; atom_n++) {
55         char buf[80];
56         int len;
57
58         len=GlobalGetAtomName( atom_list[atom_n], buf, 79);
59         if (atom_len[atom_n] != len) {
60            fprintf(stderr, "i=%d, atom_n=%d; ", i, atom_n);
61            fprintf(stderr,
62                    "wrong length of GlobalGetAtomName(\"%s\")\n",
63                    str[atom_n]);
64
65            return 1;
66         }
67            
68      }
69      for (atom_n=0 ; atom_n<TOGETHER ; atom_n++) {
70         GlobalDeleteAtom(atom_list[atom_n]);
71         if (atom_list[atom_n]!=GlobalAddAtom(str[atom_n])) {
72            fprintf(stderr, "i=%d, atom_n=%d; ", i, atom_n);
73            fprintf(stderr,
74                    "wrong third GlobalAddAtom(\"%s\")\n", str[atom_n]);
75            return 1;
76         }
77         GlobalDeleteAtom(atom_list[atom_n]);
78         GlobalDeleteAtom(atom_list[atom_n]);
79         
80         atom_list[atom_n]=GlobalAddAtom(str[atom_n]);
81         if (atom_list[atom_n]!=GlobalAddAtom(str[atom_n])) {
82            fprintf(stderr,
83                    "i=%d, atom_n=%d wrong fifth GlobalAddAtom(\"%s\")\n",
84                    i, atom_n,
85                    str[atom_n]);
86            return 1;
87         }
88         GlobalDeleteAtom(atom_list[atom_n]);
89         if (atom_list[atom_n]!=GlobalFindAtom(str[atom_n])) {
90            fprintf(stderr,
91                    "i=%d, atom_n=%d wrong GlobalFindAtom(\"%s\")\n",
92                    i, atom_n,
93                    str[atom_n]);
94            return 1;
95         }
96         GlobalDeleteAtom(atom_list[atom_n]);
97      }     
98   }
99   return 0;
100 }