From 4e84d53de8b078bdea63e9e8a882222227282462 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 28 Sep 2002 21:01:11 +0000 Subject: [PATCH] First and probably only (as it is quite generic) test app for BRoster::Launch() tests. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1248 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/app/broster/Jamfile | 3 + .../kits/app/broster/RosterTestAppDefs.h | 17 ++ src/tests/kits/app/broster/testapps/Jamfile | 79 ++++++++ .../broster/testapps/RosterLaunchTestApp1.cpp | 175 ++++++++++++++++++ 4 files changed, 274 insertions(+) create mode 100644 src/tests/kits/app/broster/Jamfile create mode 100644 src/tests/kits/app/broster/RosterTestAppDefs.h create mode 100644 src/tests/kits/app/broster/testapps/Jamfile create mode 100644 src/tests/kits/app/broster/testapps/RosterLaunchTestApp1.cpp diff --git a/src/tests/kits/app/broster/Jamfile b/src/tests/kits/app/broster/Jamfile new file mode 100644 index 0000000000..aadc5fe90d --- /dev/null +++ b/src/tests/kits/app/broster/Jamfile @@ -0,0 +1,3 @@ +SubDir OBOS_TOP src tests kits app broster ; + +SubInclude OBOS_TOP src tests kits app broster testapps ; diff --git a/src/tests/kits/app/broster/RosterTestAppDefs.h b/src/tests/kits/app/broster/RosterTestAppDefs.h new file mode 100644 index 0000000000..6a3854b8fe --- /dev/null +++ b/src/tests/kits/app/broster/RosterTestAppDefs.h @@ -0,0 +1,17 @@ +// RosterTestAppDefs.h +#ifndef ROSTER_TEST_APP_DEF_H +#define ROSTER_TEST_APP_DEF_H + +// message codes +enum { + MSG_STARTED = 'strt', // "path": B_STRING_TYPE + MSG_TERMINATED = 'term', // + MSG_ARGV_RECEIVED = 'argv', // "argc": B_INT32_TYPE, + // "argv": B_STRING_TYPE[] + MSG_REFS_RECEIVED = 'refs', // "refs": B_REF_TYPE[] + MSG_MESSAGE_RECEIVED = 'mesg', // "message": B_MESSAGE_TYPE + MSG_QUIT_REQUESTED = 'quit', // + MSG_READY_TO_RUN = 'redy', // +}; + +#endif // ROSTER_TEST_APP_DEF_H diff --git a/src/tests/kits/app/broster/testapps/Jamfile b/src/tests/kits/app/broster/testapps/Jamfile new file mode 100644 index 0000000000..8d7ed338d4 --- /dev/null +++ b/src/tests/kits/app/broster/testapps/Jamfile @@ -0,0 +1,79 @@ +SubDir OBOS_TOP src tests kits app broster testapps ; + +#SubDirHdrs [ FDirName $(OBOS_TOP) src tests kits app common ] ; +SubDirHdrs [ FDirName $(OBOS_TOP) src tests kits app broster ] ; + +UsePrivateHeaders app ; + +#local commonObjects = CommonTestApp$(SUFOBJ) ; + +rule SimpleBRosterTestApp +{ + # SimpleBRosterTestApp : : ; + local sources = $(1) ; + local resources = $(2) ; + local useObjects = $(3) ; + local name = $(sources[1]) ; + name = $(name:B) ; + SimpleBRosterTestApp2 $(name) : $(sources) : $(resources) : $(useObjects) ; +} + +rule SimpleBRosterTestApp2 +{ + # SimpleBRosterTestApp : : : ; + local name = $(1) ; + local sources = $(2) ; + local resources = $(3) ; + local useObjects = $(4) ; + local r5name = $(name)_r5 ; + + local useR5Objects ; + local object ; + for object in $(useObjects) { + useR5Objects += $(object:B=$(object:B)_r5) ; + } + + if $(resources) { + AddResources $(name) : $(resources) ; + AddResources $(r5name) : $(resources) ; + } + CommonUnitTest $(name) + : $(sources) + : kits app + : libopenbeos.so be stdc++.r4 $(useObjects) + : be stdc++.r4 $(useR5Objects) + : app support + ; +} + +rule CopyBRosterTestApp +{ + # CopyBRosterTestApp : ; + local target = $(1) ; + local source = $(2) ; + local r5target = $(target)_r5 ; + local r5source = $(source)_r5 ; + MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) kits app ] ; + MakeLocate $(r5target) : [ FDirName $(OBOS_TEST_DIR) kits app ] ; + File $(target) : $(source) ; + File $(r5target) : $(r5source) ; + local file ; + for file in $(target) $(r5target) { + MODE on $(file) = $(EXEMODE) ; + MimeSet $(file) ; + } +} + +# BRoster::Launch() test apps +# + +#local runTestApp1 = [ FGristFiles AppRunTestApp1$(SUFOBJ) ] ; + +SimpleBRosterTestApp RosterLaunchTestApp1.cpp ; +#SimpleBRosterTestApp RosterLaunchTestApp1.cpp : AppRunTestApp1.rsrc +# : $(commonObjects) ; +#SimpleBRosterTestApp2 AppRunTestApp2 : $(runTestApp1) : AppRunTestApp2.rsrc +# : $(commonObjects) ; + +#CopyBRosterTestApp AppRunTestApp3a : AppRunTestApp3 ; + diff --git a/src/tests/kits/app/broster/testapps/RosterLaunchTestApp1.cpp b/src/tests/kits/app/broster/testapps/RosterLaunchTestApp1.cpp new file mode 100644 index 0000000000..08f0783da2 --- /dev/null +++ b/src/tests/kits/app/broster/testapps/RosterLaunchTestApp1.cpp @@ -0,0 +1,175 @@ +// RosterLaunchTestApp1.cpp + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "RosterTestAppDefs.h" + +BMessenger unitTesterMessenger; + +static const char *kUnitTesterSignature + = "application/x-vnd.obos-roster-launch-test"; + +// init_unit_tester_messenger +static +status_t +init_unit_tester_messenger() +{ + // Unfortunately BeOS R5 doesn't update the roster-side information about + // the app looper's port ID once a BApplication has been created, and + // thus we can't construct a BMessenger targeting a BApplication created + // after the first one using the signature/team ID constructor. + // We need to do some hacking. + struct fake_messenger { + port_id fPort; + int32 fHandlerToken; + team_id fTeam; + int32 extra0; + int32 extra1; + bool fPreferredTarget; + bool extra2; + bool extra3; + bool extra4; + } &fake = *(fake_messenger*)&unitTesterMessenger; + // get team + status_t error = B_OK; + fake.fTeam = BRoster().TeamFor(kUnitTesterSignature); + if (fake.fTeam < 0) + error = fake.fTeam; + // find app looper port + bool found = false; + int32 cookie = 0; + port_info info; + while (error == B_OK && !found) { + error = get_next_port_info(fake.fTeam, &cookie, &info); + found = (error == B_OK && !strcmp("AppLooperPort", info.name)); + } + // init messenger + if (error == B_OK) { + fake.fPort = info.port; + fake.fHandlerToken = 0; + fake.fPreferredTarget = true; + } + return error; +} + +// get_app_path +status_t +get_app_path(char *buffer) +{ + status_t error = (buffer ? B_OK : B_BAD_VALUE); + image_info info; + int32 cookie = 0; + bool found = false; + if (error == B_OK) { + while (!found && get_next_image_info(0, &cookie, &info) == B_OK) { + if (info.type == B_APP_IMAGE) { + strncpy(buffer, info.name, B_PATH_NAME_LENGTH); + buffer[B_PATH_NAME_LENGTH] = 0; + found = true; + } + } + } + if (error == B_OK && !found) + error = B_ENTRY_NOT_FOUND; + return error; +} + +// TestApp +class TestApp : public BApplication { +public: + TestApp(const char *signature) : BApplication(signature) + { + } + + virtual void ArgvReceived(int32 argc, char **argv) + { + BMessage message(MSG_ARGV_RECEIVED); + message.AddInt32("argc", argc); + for (int32 i = 0; i < argc; i++) + message.AddString("argv", argv[i]); + unitTesterMessenger.SendMessage(&message); + } + + virtual void RefsReceived(BMessage *_message) + { + BMessage message(*_message); + message.what = MSG_REFS_RECEIVED; + unitTesterMessenger.SendMessage(&message); + } + + virtual void MessageReceived(BMessage *_message) + { + BMessage message(MSG_MESSAGE_RECEIVED); + message.AddMessage("message", _message); + unitTesterMessenger.SendMessage(&message); + } + + virtual bool QuitRequested() + { + unitTesterMessenger.SendMessage(MSG_QUIT_REQUESTED); + return true; + } + + virtual void ReadyToRun() + { + unitTesterMessenger.SendMessage(MSG_READY_TO_RUN); + } +}; + +// main +int +main() +{ + // find app file and get signature from resources + char path[B_PATH_NAME_LENGTH]; + status_t error = get_app_path(path); + char signature[B_MIME_TYPE_LENGTH]; + if (error == B_OK) { + // init app file + BFile file; + error = file.SetTo(path, B_READ_ONLY); + // get signature + BString signatureString; + if (error == B_OK) + error = file.ReadAttrString("signature", &signatureString); + else + printf("ERROR: Couldn't init app file: %s\n", strerror(error)); + // copy signature + if (error == B_OK) + strcpy(signature, signatureString.String()); + else + printf("ERROR: Couldn't get signature: %s\n", strerror(error)); + } else + printf("ERROR: Couldn't get app ref: %s\n", strerror(error)); + // create the app + TestApp *app = NULL; + if (error == B_OK) { + app = new TestApp(signature); +// unitTesterMessenger = BMessenger(kUnitTesterSignature); + error = init_unit_tester_messenger(); + if (error != B_OK) + printf("ERROR: Couldn't init messenger: %s\n", strerror(error)); + // send started message + BMessage message(MSG_STARTED); + message.AddString("path", path); + unitTesterMessenger.SendMessage(&message); + // run the app + app->Run(); + delete app; + // send terminated message + unitTesterMessenger.SendMessage(MSG_TERMINATED); + } + return 0; +} +