1 /*=========================================================================
4 Module: $RCSfile: TestCommand.cxx,v $
6 Date: $Date: 2007/05/23 14:18:06 $
7 Version: $Revision: 1.5 $
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_NAME_SPACE::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_NAME_SPACE::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_NAME_SPACE::CallbackCommand *cbk = GDCM_NAME_SPACE::CallbackCommand::New();
64 cbk->SetCallback(CallbackTest);
65 GDCM_NAME_SPACE::CommandManager::SetCommand(NULL,1,cbk);
68 CommandTest *cmd = CommandTest::New();
69 GDCM_NAME_SPACE::CommandManager::SetCommand(NULL,2,cmd);
72 std::cout << "Test on callback function execution\n";
73 GDCM_NAME_SPACE::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_NAME_SPACE::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_NAME_SPACE::CommandManager::ExecuteCommand(NULL,3,"Test on callback function");
88 std::cout << std::endl;