ProbeTest.m
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:4k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

  1. // Swarm library. Copyright (C) 1996-2000 Swarm Development Group.
  2. // This library is distributed without any warranty; without even the
  3. // implied warranty of merchantability or fitness for a particular purpose.
  4. // See file LICENSE for details and terms of copying.
  5. #import <objectbase.h>
  6. #import <objectbase/Probe.h>
  7. #import <objectbase/VarProbe.h>
  8. #import <objectbase/ProbeMap.h>
  9. #import <collections.h>
  10. #import <simtools.h>
  11. @interface TestObject: SwarmObject
  12. {
  13. @public
  14.   int firstInt;
  15.   long long longLong;
  16.   char firstChar;
  17.   char secondChar;
  18.   int secondInt;
  19.   float aFloat;
  20. }
  21. @end
  22. @implementation TestObject
  23. @end
  24. int
  25. main (int argc, const char ** argv)
  26. {
  27.   TestObject * o;
  28.   VarProbe *probe;
  29.   VarProbe *probe2;
  30.   ProbeMap * probeMap1; 
  31.   ProbeMap * probeMap2; 
  32.   char buffer[16384];
  33.   char buffer2[16384];
  34.   initSwarmBatch(argc, argv);
  35.   o = [TestObject create: globalZone];
  36.   printf("Using %sn",[o name]) ;
  37.   
  38.   probe = [VarProbe createBegin: globalZone];
  39.   [probe setProbedClass: [o class]];
  40.   [probe setProbedVariable: "secondChar"];
  41.   probe = [probe createEnd];
  42.   probe2 = [VarProbe createBegin: globalZone];
  43.   [probe2 setProbedClass: [o class]];
  44.   [probe2 setProbedVariable: "aFloat"];   
  45.   probe2 = [probe2 createEnd];
  46.   [probe2 setFloatFormat: "%.3f"];
  47.   
  48.   o->firstInt = (1<<17) + 1;
  49.   o->firstChar = 64;
  50.   o->secondChar = 32;   // the printable version of this is a space
  51.   o->secondInt = - o->firstInt;
  52.   o->longLong = 1<<31;
  53.   o->longLong *= 64;
  54.   o->aFloat = 0.675264652452;
  55.   // test setStringReturnType setting methods
  56.   printf("first proben");
  57.   printf("%sn", [probe probeAsString: o Buffer: buffer]);
  58.   if (strcmp(buffer, "32 ' '") != 0)
  59.     {
  60.       fprintf(stderr, "Default probe on char invalid n");
  61.       return 1;
  62.     }  
  63.     
  64.   [probe setStringReturnType: CharString] ;
  65.   printf("%sn", [probe probeAsString: o Buffer: buffer]);
  66.   if (strcmp(buffer, "' '") != 0)
  67.     {
  68.       fprintf(stderr, "Char probe on char invalid n");
  69.       return 1;
  70.     }  
  71.   
  72.   [probe setStringReturnType: IntString] ;
  73.   printf("%sn", [probe probeAsString: o Buffer: buffer]);
  74.   if (strcmp(buffer, "32") != 0)
  75.     {
  76.       fprintf(stderr, "Int probe on char invalid n");
  77.       return 1;
  78.     }  
  79.   // test access to precision probing directly via VarProbes
  80.   printf("second proben");
  81.   printf("%sn", [probe2 probeAsString: o Buffer: buffer2]);
  82.   if (strcmp(buffer2, "0.675") != 0)
  83.     {
  84.       fprintf(stderr, "Probe on float not returning correct precisionn");
  85.       return 1;
  86.     }
  87.   // test access to precision probing via ProbeMaps
  88.   probeMap1 = [EmptyProbeMap createBegin: globalZone];
  89.   [probeMap1 setProbedClass: [o class]];
  90.   probeMap1 = [probeMap1 createEnd];
  91.   printf("first ProbeMapn");
  92.   [probeMap1 addProbe: 
  93.                [probeLibrary getProbeForVariable: "aFloat"
  94.                              inClass: [o class]]];
  95.   
  96.   [probeLibrary setProbeMap: probeMap1 For: [o class]];
  97.   printf("%sn", [[probeLibrary getProbeForVariable: "aFloat" inClass: [o class]]
  98.                    probeAsString: o Buffer: buffer]);
  99.   
  100.   if (strcmp(buffer, "0.675") == 0)
  101.     {
  102.       fprintf(stderr, "Probe on float installed in global `probeLibrary' not returning enough precision n");
  103.       return 1;
  104.     }
  105.   // override probeMap1 by probeMap2 in probeLibrary for `TestObject' class
  106.   printf("second ProbeMapn");
  107.   probeMap2 = [EmptyProbeMap createBegin: globalZone];
  108.   [probeMap2 setProbedClass: [o class]];
  109.   probeMap2 = [probeMap2 createEnd];
  110.   [probeMap2 addProbe: 
  111.               [[probeLibrary getProbeForVariable: "aFloat"
  112.                              inClass: [o class]] setFloatFormat: "%.3f"]];
  113.   
  114.   [probeLibrary setProbeMap: probeMap2 For: [o class]];
  115.   
  116.   printf("%sn", [[probeLibrary getProbeForVariable: "aFloat" inClass: [o class]]
  117.                    probeAsString: o Buffer: buffer]);
  118.   
  119.   if (strcmp(buffer, "0.675") != 0)
  120.     {
  121.       fprintf(stderr, "Probe on float installed in global `probeLibrary' instance not returning 3 sig fig precisionn");
  122.       return 1;
  123.     }
  124.   
  125.   return 0;
  126. }