home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / info / document / access / acstest.c < prev    next >
C/C++ Source or Header  |  1993-11-12  |  7KB  |  188 lines

  1. //----------------------------------------------------------
  2. //
  3. // ACSTEST.C -- Test the AccessWPS Agent to verify it is working
  4. //
  5. //----------------------------------------------------------
  6. #pragma strings(readonly)
  7. #define OFF        0
  8. #define ON         1
  9. #ifndef NO
  10. #define NO         0
  11. #endif
  12. #ifndef YES
  13. #define YES        1
  14. #endif
  15. #define GOOD       0
  16. #define BAD        1
  17. typedef unsigned long APRINI;
  18. typedef int SIGNED;
  19. typedef SIGNED *PSIGNED;
  20. typedef unsigned int UNSIGNED;
  21. typedef UNSIGNED *PUNSIGNED;
  22. #define MAXNAME    255
  23. #define GROUPNAME  50
  24. #define null       '\0'
  25. #define THREAD_STACK_SIZE     81920
  26. #define INCL_BASE
  27. #define INCL_WIN
  28. #define INCL_GPI
  29. #define INCL_DEV
  30. #define INCL_DOS
  31. #define INCL_DOSERRORS
  32. #define INCL_SPLERRORS
  33. #define INCL_SHLERRORS
  34. #define INCL_WINSTDDRAG
  35. #include <conio.h>
  36. #include <fcntl.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <os2.h>
  40. #include <stdio.h>
  41. #include <ctype.h>
  42. #include <mscsubs.h>
  43. #include <time.h>
  44. #include <io.h>
  45. #include <memory.h>
  46. #include <malloc.h>
  47. #include <search.h>
  48. #include <math.h>
  49. #include <direct.h>
  50. #include <process.h>
  51. #include <types.h>
  52. #include <stat.h>
  53. #include "accsswps.h"
  54. VOID AcsTestThread(PVOID);
  55. HWND         hwndFrame, hwndListbox;
  56. CHAR         chMessage[MAXNAME];
  57. int main (void) {
  58.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
  59.                                  FCF_SIZEBORDER    | FCF_MINMAX  |
  60.                                  FCF_SHELLPOSITION | FCF_TASKLIST;
  61.    HAB          hab;
  62.    HMQ          hmq;
  63.    QMSG         qmsg;
  64.    HPOINTER     hpTemp;
  65.    hab = WinInitialize(0);
  66.    hmq = WinCreateMsgQueue(hab, 0);
  67.    hwndFrame = WinCreateStdWindow(
  68.       HWND_DESKTOP,                   // Parent window handle
  69.       WS_VISIBLE,                     // Style of frame window
  70.       &flFrameFlags,                  // Pointer to control data
  71.       WC_LISTBOX,                     // Make it a Listbox
  72.       (PSZ)"AccessWPS Test",          // Title bar text
  73.       LS_NOADJUSTPOS | LS_HORZSCROLL, // Style of client window
  74.       0,                              // Module handle for resources
  75.       0,                              // ID of resources
  76.       &hwndListbox);                   // Pointer to client window handle
  77.    hpTemp = WinQuerySysPointer(HWND_DESKTOP, SPTR_APPICON, FALSE);
  78.    (VOID)WinSendMsg(hwndFrame, WM_SETICON, MPFROMP(hpTemp), 0L);
  79.    (VOID)DosBeep(261, 100);
  80.    (VOID)DosBeep(330, 100);
  81.    (VOID)DosBeep(392, 100);
  82.    (VOID)DosBeep(523, 500);
  83.    if (_beginthread(AcsTestThread, (PVOID)NULL, THREAD_STACK_SIZE, NULL)
  84.       == -1) {
  85.       sprintf(chMessage, "AcsAgent Test Thread Could not be Started");
  86.       (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  87.          MPFROMP(chMessage));
  88.    }
  89.    while (WinGetMsg(hab, &qmsg, NULL, 0, 0))
  90.         (VOID)WinDispatchMsg(hab, &qmsg);
  91.    (VOID)WinDestroyWindow(hwndFrame);
  92.    (VOID)WinDestroyMsgQueue(hmq);
  93.    (VOID)WinTerminate(hab);
  94.    (VOID)DosBeep(523, 100);
  95.    (VOID)DosBeep(392, 100);
  96.    (VOID)DosBeep(330, 100);
  97.    (VOID)DosBeep(261, 500);
  98.    exit(0);
  99. }
  100. VOID AcsTestThread(PVOID pvPassed)
  101. {
  102.    HAB         habThread;
  103.    HMQ         hmqThread;
  104.    PCHAR       pchMessage;
  105.    BOOL        fAcsErr;
  106. // the only real purpose for the pchMessage variable is to keep PC Lint
  107. //    from conplaining that the pvPassed variable...which is NULL...is
  108. //    not used. it is used a few places below, but chMessage could have
  109. //    been used also.
  110.    pchMessage = (PCHAR)pvPassed;
  111. // set up an anchor block for the thread
  112.    habThread = WinInitialize(0);
  113.    hmqThread = WinCreateMsgQueue(habThread, 0);
  114. // indicate the thread has been started
  115.    pchMessage = chMessage;
  116.    sprintf(chMessage, "AcsAgent Test Thread Started");
  117.    (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  118.       MPFROMP(chMessage));
  119. // initialize the agent object
  120.    sprintf(chMessage, "Starting AcsAgent Object Creation");
  121.    (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  122.       MPFROMP(chMessage));
  123.    if (AcsInit() != NO_ERROR) {
  124.       fAcsErr = AcsReturnError();
  125.       sprintf(chMessage, "AcsAgent Object Creation Failed Error = %u",
  126.          fAcsErr);
  127.       (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  128.          MPFROMP(chMessage));
  129.    // if we got an error, we do not want to try to get the version
  130.       goto do_dump;
  131.    }
  132.    else {
  133.       sprintf(chMessage, "AcsAgent Object Creation Successful");
  134.       (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  135.          MPFROMP(chMessage));
  136.    }
  137.    sprintf(chMessage, "Getting Version Information");
  138.    (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  139.       MPFROMP(chMessage));
  140.    memset(chMessage, null, MAXNAME);
  141.    AcsVersion(chMessage);
  142.    if (chMessage[0] == null)
  143.       sprintf(chMessage, "Version Information Could not be Obtained");
  144.    (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  145.       MPFROMP(chMessage));
  146. do_dump:
  147. // do the dump of the agent stuff
  148.    sprintf(chMessage, "Starting AcsAgent Object Variable Dump");
  149.    (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  150.       MPFROMP(chMessage));
  151. dump_more:
  152.    memset(chMessage, null, MAXNAME);
  153.    fAcsErr = AcsDumpLine(chMessage);
  154.    if (chMessage[0] != null) {
  155.       (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  156.          MPFROMP(chMessage));
  157.    }
  158.    if (fAcsErr == TRUE) goto dump_more;
  159.    sprintf(chMessage, "AcsAgent Object Variable Dump Completed");
  160.    (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  161.       MPFROMP(chMessage));
  162. // terminate the agent object
  163.    sprintf(chMessage, "Starting AcsAgent Object Termination");
  164.    (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  165.       MPFROMP(chMessage));
  166.    if (AcsTerminate() != NO_ERROR) {
  167.       fAcsErr = AcsReturnError();
  168.       sprintf(chMessage, "AcsAgent Object Termination Failed Error = %u",
  169.          fAcsErr);
  170.       (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  171.          MPFROMP(chMessage));
  172.    }
  173.    else {
  174.       sprintf(chMessage, "AcsAgent Object Termination Successful");
  175.       (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  176.          MPFROMP(chMessage));
  177.    }
  178. // indicate the thread is ending
  179.    sprintf(chMessage, "AcsAgent Test Thread Terminating");
  180.    (VOID)WinSendMsg(hwndListbox, LM_INSERTITEM, MPFROMSHORT(LIT_END),
  181.       MPFROMP(chMessage));
  182. // destroy the anchor block
  183.    (VOID)WinDestroyMsgQueue(hmqThread);
  184.    (VOID)WinTerminate(habThread);
  185. // end the thread
  186.    _endthread();
  187. }
  188.