home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / ADDON.PAK / EDITTEST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  6.9 KB  |  282 lines

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   edittest.cpp
  4.   Created: 10/24/95
  5.   Copyright (c) 1995, Borland International
  6.   $Revision:   1.19  $
  7.    
  8. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/  
  9. #ifndef __AOEXPCH_H
  10.   #include "aoexpch.h"
  11. #endif
  12. #pragma hdrstop
  13.  
  14. #include "edittest.h"
  15.  
  16. //.............................................................................
  17. EditTestA::EditTestA() 
  18.   {
  19.   _editServer = NULL;
  20.   }
  21. //.............................................................................
  22. EditTestA::~EditTestA() 
  23.   {
  24.   UnInit();
  25.   }
  26. //.............................................................................
  27. BOOL EditTestA::Init() 
  28.   {
  29.   if ( !_editServer ) 
  30.     {
  31.     OutStr( "EditTestA::Init()" );
  32.     _editServer = GET_INTERFACE(IEditorServer);
  33.     if ( _editServer == NULL ) 
  34.       {
  35.       return FALSE;
  36.       }
  37.     }
  38.   return TRUE;
  39. }
  40. //.............................................................................
  41. void EditTestA::UnInit() 
  42.   {
  43.   OutStr( "EditTestA::UnInit()" );
  44.   if ( _editServer ) 
  45.     {
  46.     _editServer->Release();
  47.     _editServer = NULL;
  48.     }
  49.   }
  50. //.............................................................................
  51. const char * EditTestA::GetName() 
  52.   {
  53.   return "Editor server tests";
  54.   }
  55. //.............................................................................
  56. const char * EditTestA::GetTestDescription( int testNum ) 
  57.   {
  58.   switch ( testNum )
  59.     {
  60.     case 1: 
  61.       return "Comment the current line.";
  62.     case 2: 
  63.       return "Return the length of the current line.";
  64.     case 3: 
  65.       return "Convert the current line to upper case.";
  66.     case 4: 
  67.       return "Return info about the current buffer.";
  68.     }
  69.   return "This test not implemented.";
  70.   }  
  71. //.............................................................................
  72. void EditTestA::DoTest( int testNum ) 
  73.   {
  74.   if ( !_editServer ) 
  75.     {
  76.     OutStr( "Editor Server not initialized!" );
  77.     return;
  78.     }
  79.   switch ( testNum ) 
  80.     {  
  81.     case 1: 
  82.       {
  83.       IPolyString *comment = ::MakePolyString ("//");
  84.       if (comment != NULL)
  85.         {
  86.         _editServer->begin_edit();
  87.         BufferId bid = _editServer->inq_buffer();
  88.         if ( bid )
  89.           {
  90.           _editServer->beginning_of_line();
  91.           _editServer->insert( comment );
  92.           _editServer->down();
  93.           }
  94.         _editServer->end_edit();
  95.         }
  96.       else 
  97.         {
  98.         OutStr( FormatStr( "Failure to make a polystr." ) );
  99.         }
  100.       }
  101.       break;
  102.  
  103.     case 2: 
  104.       {
  105.       _editServer->begin_edit();
  106.       BufferId bid = _editServer->inq_buffer();
  107.       if ( bid )
  108.         {
  109.         OutStr( FormatStr( "Line length = %d", _editServer->inq_line_length() ) );
  110.         }
  111.       _editServer->end_edit();
  112.       }
  113.       break;
  114.  
  115.     case 3: 
  116.       {
  117.       _editServer->begin_edit();
  118.       BufferId bid = _editServer->inq_buffer();
  119.       if ( bid )
  120.         {
  121.         _editServer->beginning_of_line();
  122.         IPolyString *chars = _editServer->read();
  123.         if ( chars )
  124.           {
  125.           _editServer->delete_line();
  126.           int len = strlen( chars->GetCstr() );
  127.           char *newchars = new char[len + 1]; 
  128.           if ( newchars )
  129.             {
  130.             strcpy ( newchars, chars->GetCstr() );
  131.             strupr ( newchars );
  132.             IPolyString *poly = ::MakePolyString (newchars);
  133.             if (poly != NULL)
  134.               {
  135.               _editServer->insert( poly );
  136.               }
  137.             delete[] newchars;
  138.             }
  139.           chars->Release();
  140.           }
  141.         }
  142.       _editServer->end_edit();
  143.       }
  144.       break;
  145.  
  146.     case 4: 
  147.       {
  148.       _editServer->begin_edit();
  149.       BufferId bid = _editServer->inq_buffer();
  150.       if ( bid )
  151.         {
  152.         IPolyString *name = NULL;
  153.         IPolyString *ext = NULL;
  154.         IPolyString *bufname = NULL;
  155.  
  156.         _editServer->inq_names( &name, &ext, &bufname );
  157.  
  158.         if ( name )
  159.           ShowPolyStr ("File name = ", name, TRUE);
  160.         if ( ext )
  161.           ShowPolyStr ("Extension = ", ext, TRUE);
  162.         if ( bufname )
  163.           ShowPolyStr ("Buffer name = ", bufname, TRUE);
  164.         }
  165.       _editServer->end_edit();
  166.       }
  167.       break;
  168.  
  169.     default: 
  170.       {
  171.       OutStr( FormatStr( "Test #%d Not Implemented!", testNum ) );
  172.       }
  173.     }
  174.   }
  175.  
  176.  
  177.  
  178. //////////////////////////////////////////////////////////////////////////////
  179. //
  180. //  Edit Test B
  181. //
  182. //////////////////////////////////////////////////////////////////////////////
  183.  
  184.  
  185. //.............................................................................
  186. EditTestB::EditTestB() 
  187.   {
  188.   _editServer = NULL;
  189.   }
  190. //.............................................................................
  191. EditTestB::~EditTestB() 
  192.   {
  193.   UnInit();
  194.   }
  195. //.............................................................................
  196. BOOL EditTestB::Init() 
  197.   {
  198.   if ( !_editServer ) 
  199.     {
  200.     OutStr( "EditTestB::Init()" );
  201.     _editServer = GET_INTERFACE(IEditorServer);
  202.     if ( _editServer == NULL ) 
  203.       {
  204.       return FALSE;
  205.       }
  206.     }
  207.   return TRUE;
  208. }
  209. //.............................................................................
  210. void EditTestB::UnInit() 
  211.   {
  212.   OutStr( "EditTestB::UnInit()" );
  213.   if ( _editServer ) 
  214.     {
  215.     _editServer->Release();
  216.     _editServer = NULL;
  217.     }
  218.   }
  219. //.............................................................................
  220. const char * EditTestB::GetName() 
  221.   {
  222.   return "Editor undo/redo";
  223.   }
  224. //.............................................................................
  225. const char * EditTestB::GetTestDescription( int testNum ) 
  226.   {
  227.   switch ( testNum )
  228.     {
  229.     case 1: 
  230.       return "Is undo Available?";
  231.     case 2: 
  232.       return "Perform the undo.";
  233.     case 3: 
  234.       return "Is redo Available?";
  235.     case 4: 
  236.       return "Perform the redo.";
  237.     }
  238.   return "This test not implemented.";
  239.   }  
  240. //.............................................................................
  241. void EditTestB::DoTest( int testNum ) 
  242.   {
  243.   if ( !_editServer ) 
  244.     {
  245.     OutStr( "Editor Server not initialized!" );
  246.     return;
  247.     }
  248.   switch ( testNum ) 
  249.     {  
  250.     case 1: 
  251.       if ( _editServer->undo_available() )
  252.         OutStr( "Undo is available.");
  253.       else
  254.         OutStr( "Undo is not available.");
  255.       break;
  256.  
  257.     case 2: 
  258.       _editServer->begin_edit();
  259.       _editServer->undo();
  260.       _editServer->end_edit();
  261.       break;
  262.  
  263.     case 3: 
  264.       if ( _editServer->redo_available() )
  265.         OutStr( "Redo is available.");
  266.       else
  267.         OutStr( "Redo is not available.");
  268.       break;
  269.  
  270.     case 4: 
  271.       _editServer->begin_edit();
  272.       _editServer->redo();
  273.       _editServer->end_edit();
  274.       break;
  275.  
  276.     default: 
  277.       {
  278.       OutStr( FormatStr( "Test #%d Not Implemented!", testNum ) );
  279.       }
  280.     }
  281.   }
  282.