home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / som / somk / cpp / derived / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-24  |  2.7 KB  |  84 lines

  1.  
  2. //
  3. //   COMPONENT_NAME: somx
  4. //
  5. //   ORIGINS: 27
  6. //
  7. //
  8. //   10H9767, 10H9769  (C) COPYRIGHT International Business Machines Corp. 1992,1994
  9. //   All Rights Reserved
  10. //   Licensed Materials - Property of IBM
  11. //   US Government Users Restricted Rights - Use, duplication or
  12. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  13. //
  14. /* %Z% %I% %W% %G% %U% [%H% %T%] */
  15.  
  16. /*
  17.  *
  18.  * DISCLAIMER OF WARRANTIES.
  19.  * The following [enclosed] code is sample code created by IBM
  20.  * Corporation. This sample code is not part of any standard or IBM
  21.  * product and is provided to you solely for the purpose of assisting
  22.  * you in the development of your applications.  The code is provided
  23.  * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
  24.  * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25.  * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF
  26.  * THIS CODE.  IBM shall not be liable for any damages arising out of
  27.  * your use of the sample code, even if they have been advised of the
  28.  * possibility of such damages.
  29.  *
  30.  * DISTRIBUTION.
  31.  * This sample code can be freely distributed, copied, altered, and
  32.  * incorporated into other software, provided that it bears the above
  33.  * Copyright notice and DISCLAIMER intact.
  34.  */
  35.  
  36. #include "derived.xh"
  37. #include "nlsutil.h"
  38. #include "msgid.h"
  39. #include <stdio.h>
  40. #include <string.h>
  41.  
  42.  
  43. class X {
  44.   public:
  45.     X() { a = 1; };
  46.     long a;
  47.     virtual void test() { SOM_Test(a == 1); }
  48. };
  49.     
  50.  
  51. int main(int argc, char *argv[])
  52. {
  53.  
  54.     Derived *test = new Derived;
  55.  
  56.     SOM_Test(!strcmp(test->somGetClassName(),"Derived"));
  57.     SOM_Test(!strcmp(test->somGetClass()->somGetClassName(),"M_Derived_Derived"));
  58.  
  59.     SOM_Test(test->somRespondsTo(somIdFromString("hello_")) == 1);
  60.     SOM_Test(!strcmp(test->hello_(),"Hello World"));
  61.     SOM_Test(test->somRespondsTo(somIdFromString("mello_")) == 1);
  62.     SOM_Test(!strcmp(test->mello_(),"Mello World"));
  63.  
  64.     SOM_Test(test->somGetClass()->somRespondsTo(somIdFromString("HelloCreate")) == 1);
  65.     Hello *a = ((M_Hello*) (test->somGetClass()))->HelloCreate("Hello from A");
  66.     SOM_Test(!strcmp(a->hello_(),"Hello from A"));
  67.  
  68.     SOM_Test(test->somGetClass()->somRespondsTo(somIdFromString("MelloCreate")) == 1);
  69.     Mello *b = ((M_Mello*) (test->somGetClass()))->MelloCreate("Mello from B");
  70.     SOM_Test(!strcmp(b->mello_(),"Mello from B"));
  71.  
  72.     Hello *c = (Hello*) (test->somGetClass()->somNew());
  73.     Mello *d = (Mello*) (test->somGetClass()->somNew());
  74.  
  75.     SOM_Test(!strcmp(c->hello_(),"Hello World"));
  76.     SOM_Test(!strcmp(d->mello_(),"Mello World"));
  77.  
  78.  
  79.     X *x = new X;
  80.     x->test();
  81.     printf(NlsMsgGet(SuccessId));
  82.     return 0;
  83. }
  84.