1 /*=========================================================================
4 Module: $RCSfile: TestCommand.cxx,v $
6 Date: $Date: 2005/11/30 08:48:15 $
7 Version: $Revision: 1.4 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
18 #include "gdcmCommand.h"
19 #include "gdcmCallbackCommand.h"
20 #include "gdcmCommandManager.h"
25 class CommandTest : public gdcm::Command
27 gdcmTypeMacro(CommandTest);
28 gdcmNewMacro(CommandTest);
31 virtual void Execute()
33 std::cout << "Test class command... for "
34 << typeid(GetObject()).name()
35 << " (" << GetObject() << ")" << std::endl
36 << GetText() << std::endl;
40 bool IsExecuted() {return Executed;}
43 CommandTest() {Executed = false;}
48 static bool fctExecuted = false;
49 void CallbackTest(gdcm::CallbackCommand *cmd)
51 std::cout << "Test class command... for "
52 << typeid(cmd->GetObject()).name()
53 << " (" << cmd->GetObject() << ")" << std::endl
54 << cmd->GetText() << std::endl;
59 int TestCommand(int , char *[])
63 gdcm::CallbackCommand *cbk = gdcm::CallbackCommand::New();
64 cbk->SetCallback(CallbackTest);
65 gdcm::CommandManager::SetCommand(NULL,1,cbk);
68 CommandTest *cmd = CommandTest::New();
69 gdcm::CommandManager::SetCommand(NULL,2,cmd);
72 std::cout << "Test on callback function execution\n";
73 gdcm::CommandManager::ExecuteCommand(NULL,1,"Test on callback function");
75 std::cout<<"... Failed\n";
77 std::cout << std::endl;
79 std::cout << "Test on command class execution\n";
80 gdcm::CommandManager::ExecuteCommand(NULL,2,"Test on command class");
81 if(!cmd->IsExecuted())
82 std::cout<<"... Failed\n";
83 error+=!cmd->IsExecuted();
84 std::cout << std::endl;
86 std::cout << "Test on unset command execution\n";
87 gdcm::CommandManager::ExecuteCommand(NULL,3,"Test on callback function");
88 std::cout << std::endl;