home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk12 / ddeml / test.c < prev   
Encoding:
C/C++ Source or Header  |  1990-06-22  |  7.7 KB  |  239 lines

  1. #define INCL_WINCATCHTHROW 
  2. #include "ddemlp.h"
  3. #include "stdio.h"
  4.  
  5. int    APIENTRY DebugOutput( PCH );        /* private import */
  6. CATCHBUF catchbuf;
  7.  
  8. void DumpItems(PULONG pul, USHORT c);
  9. void err(PSZ psz);
  10. void err2(PSZ psz, ULONG ul);
  11.  
  12. typedef struct _ULLI {
  13.     PLITEM next;
  14.     ULONG ul;
  15. } ULLI;
  16. typedef ULLI FAR *PULLI;
  17.  
  18. /*
  19.  * exported for testing the DLL
  20.  */
  21. void EXPENTRY DdeTest()
  22. {
  23. #if 0    
  24.     SEL sel;
  25.     USHORT c;
  26.     ULLI SchItem;
  27.     PLST plst;
  28.     PPILE ppile;
  29.     HHEAP hheap;
  30.     PLITEM pli;
  31.     PBYTE pbytes;
  32.  
  33.     AssertF(FALSE, "Testing assertion failure");
  34.     
  35.     DebugOutput("\n\rList functions test\n\r");
  36.     SemEnter();
  37.     if (DosAllocSeg(2000, &sel, SEG_NONSHARED))
  38.         err("DosAllocSeg failed");
  39.     if (!(hheap = MyCreateHeap(sel, 0, 0, 0, 0, HEAPFLAGS)))
  40.         err("CreateHeap failed");
  41.     if (!(pbytes = FarAllocMem(hheap, 1000)))
  42.         err("Could not allocate bytes");
  43.     plst = NULL;
  44.     SchItem.ul = 4L;
  45.     SemLeave();
  46.     DebugOutput("\n\rNULL list test....");
  47.     SemEnter();
  48.     DestroyLst(plst);
  49.     FlushLst(plst);
  50.     FindLstItem(plst, CmpULONG, (PLITEM)&SchItem);
  51.     FindLstItem(plst, CmpULONG, NULL);
  52.     FindLstItem(plst, NULL, (PLITEM)&SchItem);
  53.     FindLstItem(plst, NULL, NULL);
  54.     NewLstItem(plst, ILST_NOLINK);
  55.     NewLstItem(plst, ILST_FIRST);
  56.     NewLstItem(plst, ILST_LAST);
  57.     PopLi(plst);
  58.     RemoveLstItem(plst, (PLITEM)&SchItem);
  59.     RemoveLstItem(plst, NULL);
  60.     InsertLstItem(plst, (PLITEM)&SchItem, ILST_FIRST);
  61.     SemLeave();
  62.     DebugOutput("\n\rCreateList...");
  63.     SemEnter();
  64.     plst = CreateLst(hheap, sizeof(ULONG));
  65.     if (!plst) 
  66.         err("CreateLst() failed");
  67.     pli = NewLstItem(plst, ILST_FIRST);
  68.     if (!pli)
  69.         err("NewLstItem() failed");
  70.     ((PULLI)pli)->ul = 1L;
  71.     SchItem.ul = 1L;
  72.     if (pli != FindLstItem(plst, CmpULONG, (PLITEM)&SchItem))
  73.         err("FindLstItem() failed");
  74.     if (pli != PopLi(plst)) {
  75.         err("PopLi() failed");
  76.     }
  77.     if (FindLstItem(plst, NULL, NULL)) 
  78.         err("unexpected success of FindLstItem()");
  79.     for (SchItem.ul = 1L; SchItem.ul < 100L; SchItem.ul++) {
  80.         if (!(pli = NewLstItem(plst, ILST_FIRST)))
  81.             err("NewLstItem() failed");
  82.         ((PULLI)pli)->ul = SchItem.ul;
  83.         if (!FindLstItem(plst, CmpULONG, (PLITEM)&SchItem))
  84.             err2("Item %ul not found", SchItem.ul);
  85.     }
  86.     SchItem.ul = 25L;
  87.     if (!RemoveLstItem(plst, FindLstItem(plst, CmpULONG, (PLITEM)&SchItem)))
  88.         err2("RemoveLstItem() failed on %ul", SchItem.ul);
  89.     SchItem.ul = 47L;
  90.     if (!RemoveLstItem(plst, FindLstItem(plst, CmpULONG, (PLITEM)&SchItem)))
  91.         err2("RemoveLstItem() failed on %ul", SchItem.ul);
  92.     SchItem.ul = 78L;
  93.     if (!RemoveLstItem(plst, FindLstItem(plst, CmpULONG, (PLITEM)&SchItem)))
  94.         err2("RemoveLstItem() failed on %ul", SchItem.ul);
  95.     for (SchItem.ul = 1L; SchItem.ul < 100L; SchItem.ul++) {
  96.         if (SchItem.ul == 25L || SchItem.ul == 47L || SchItem.ul == 78L) {
  97.             if (FindLstItem(plst, CmpULONG, (PLITEM)&SchItem))
  98.                 err2("Unexpected find of %ul", SchItem.ul);
  99.         } else if (!FindLstItem(plst, CmpULONG, (PLITEM)&SchItem))
  100.             err2("Unexpected failure to find %ul", SchItem.ul);
  101.     }
  102.     FlushLst(plst);
  103.     if (PopLi(plst))
  104.         err("Unexpected pass of PopLi()");
  105.     DestroyLst(plst);
  106.     plst = NULL;
  107.     SemLeave();
  108.     DebugOutput("\n\rList test passed.\n\r");
  109.  
  110.  
  111.     DebugOutput("\n\rNULL Pile test...");
  112.     SemEnter();
  113.     ppile = NULL;
  114.     DestroyPile(ppile);
  115.     FlushPile(ppile);
  116.     if (QPileItemCount(ppile))
  117.         err("Unexpected pass of QPileItemCount()");
  118.     if (CopyPileItems(ppile, pbytes))
  119.         err("Unexpected pass of CopyPileItems()");
  120.     if (FindPileItem(ppile, NULL, NULL, FPI_COUNT))
  121.         err("Wrong count from FindPileItem()");
  122.     if (FindPileItem(ppile, NULL, NULL, FPI_DELETE))
  123.         err("Unexpected pass of FindPileItem()");
  124.     if (AddPileItem(ppile, NULL, NULL))
  125.         err("Unexpected pass of AddPileItem()");
  126.     
  127.     SemLeave();
  128.     DebugOutput("\n\rPile test...");
  129.     SemEnter();
  130.     if (!(ppile = CreatePile(hheap, sizeof(ULONG), 8)))
  131.         err("Unexpected failure of CreatePile()");
  132.     for (SchItem.ul = 1L; SchItem.ul < 100; SchItem.ul++) {
  133.         AddPileItem(ppile, (PBYTE)&SchItem.ul, CmpULONG);
  134.         if (SchItem.ul > 25) 
  135.             if (AddPileItem(ppile, (PBYTE)&SchItem.ul, CmpULONG))
  136.                 err("Unexpected TRUE(1) return by AddPileItem()");
  137.         if (SchItem.ul > 50) 
  138.             if (AddPileItem(ppile, (PBYTE)&SchItem.ul, CmpULONG))
  139.                 err("Unexpected TRUE(2) return by AddPileItem()");
  140.         if (SchItem.ul > 75) 
  141.             if (AddPileItem(ppile, (PBYTE)&SchItem.ul, CmpULONG))
  142.                 err("Unexpected TRUE(3) return by AddPileItem()");
  143.     }
  144.     if (QPileItemCount(ppile) != 99)
  145.         err("Total pile count wrong");
  146.     for (SchItem.ul = 1L; SchItem.ul < 100L; SchItem.ul++) {
  147.         if (1 != (USHORT)FindPileItem(ppile, CmpULONG, (PBYTE)&SchItem.ul, FPI_COUNT))
  148.             err("Wrong count of items found by FindPileItem()");
  149.     }                                                 
  150.     for (SchItem.ul = 26L; SchItem.ul < 100L; SchItem.ul++) {
  151.         AddPileItem(ppile, (PBYTE)&SchItem.ul, NULL);
  152.         if (SchItem.ul > 50) 
  153.             if (!AddPileItem(ppile, (PBYTE)&SchItem.ul, NULL))
  154.                 err("Unexpected FALSE(2) return by AddPileItem()");
  155.         if (SchItem.ul > 75) 
  156.             if (!AddPileItem(ppile, (PBYTE)&SchItem.ul, NULL))
  157.                 err("Unexpected FALSE(3) return by AddPileItem()");
  158.     }
  159.     for (SchItem.ul = 1L; SchItem.ul < 26L; SchItem.ul++) {
  160.         c = (USHORT)FindPileItem(ppile, CmpULONG, (PBYTE)&SchItem.ul, FPI_COUNT);
  161.         if (c != 1)
  162.             err("Wrong count of items found by FindPileItem()");
  163.     }                                                 
  164.     for (SchItem.ul = 26L; SchItem.ul < 51L; SchItem.ul++) {
  165.         c = (USHORT)FindPileItem(ppile, CmpULONG, (PBYTE)&SchItem.ul, FPI_COUNT);
  166.         if (c != 2)
  167.             err("Wrong count of items found by FindPileItem()");
  168.     }                                                 
  169.     for (SchItem.ul = 51L; SchItem.ul < 76L; SchItem.ul++) {
  170.         c = (USHORT)FindPileItem(ppile, CmpULONG, (PBYTE)&SchItem.ul, FPI_COUNT);
  171.         if (c != 3)
  172.             err("Wrong count of items found by FindPileItem()");
  173.     }                                                 
  174.     for (SchItem.ul = 76L; SchItem.ul < 100L; SchItem.ul++) {
  175.         c = (USHORT)FindPileItem(ppile, CmpULONG, (PBYTE)&SchItem.ul, FPI_COUNT);
  176.         if (c != 4)
  177.             err("Wrong count of items found by FindPileItem()");
  178.     }
  179.     if ((c = QPileItemCount(ppile)) != 99 + 74 + 49 + 24)
  180.         err("Total pile count wrong");
  181.     CopyPileItems(ppile, pbytes);
  182.     DestroyPile(ppile);
  183.     SemLeave();
  184.     DumpItems((PULONG)pbytes, c);
  185.     MyDestroyHeap(hheap);
  186. #endif    
  187.     return;
  188. }
  189.  
  190.  
  191.  
  192. void DumpItems(pul, c)
  193. PULONG pul;
  194. USHORT c;
  195. {
  196.     char sz[100];
  197.     char far *psz;
  198.  
  199.     psz = sz;
  200.     while (c--) {
  201.         if ((c % 7) == 0) {
  202.             *psz++ = '\n';
  203.             *psz++ = '\r';
  204.             *psz++ = '\0';
  205.             DebugOutput(sz);
  206.             psz = sz;
  207.         }
  208.         psz = ltoa(*pul, psz, &sz[99]);
  209.         *psz++ = ' ';
  210.         pul++;
  211.     }
  212.     *psz++ = '\n';
  213.     *psz++ = '\r';
  214.     *psz++ = '\0';
  215.     DebugOutput(sz);
  216. }
  217.  
  218.  
  219.  
  220. void err(psz)
  221. PSZ psz;
  222. {
  223.     SemLeave();
  224.     DebugOutput(psz);
  225. }
  226.  
  227. void err2(psz, ul)
  228. PSZ psz;
  229. ULONG ul;
  230. {
  231.     char sz[80];
  232.  
  233.     SemLeave();
  234.     sz[0] = '\000';
  235.     psz = lstrcat(sz, psz, &sz[79]);
  236.     psz = ltoa(ul, psz, &sz[79]);
  237.     DebugOutput(sz);
  238. }
  239.