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
This commit is contained in:
Ingo Weinhold 2002-09-28 21:01:11 +00:00
parent 51cd5541a4
commit 4e84d53de8
4 changed files with 274 additions and 0 deletions

View File

@ -0,0 +1,3 @@
SubDir OBOS_TOP src tests kits app broster ;
SubInclude OBOS_TOP src tests kits app broster testapps ;

View File

@ -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

View File

@ -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 = <src!tests!kits!app!common>CommonTestApp$(SUFOBJ) ;
rule SimpleBRosterTestApp
{
# SimpleBRosterTestApp <sources> : <resources> : <use objects> ;
local sources = $(1) ;
local resources = $(2) ;
local useObjects = $(3) ;
local name = $(sources[1]) ;
name = $(name:B) ;
SimpleBRosterTestApp2 $(name) : $(sources) : $(resources) : $(useObjects) ;
}
rule SimpleBRosterTestApp2
{
# SimpleBRosterTestApp <name> : <sources> : <resources> : <use objects> ;
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
: <boot!home!config!lib>libopenbeos.so be stdc++.r4 $(useObjects)
: be stdc++.r4 $(useR5Objects)
: app support
;
}
rule CopyBRosterTestApp
{
# CopyBRosterTestApp <target> : <source> ;
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 ;

View File

@ -0,0 +1,175 @@
// RosterLaunchTestApp1.cpp
#include <stdio.h>
#include <string.h>
#include <Application.h>
#include <Entry.h>
#include <File.h>
#include <Message.h>
#include <Messenger.h>
#include <OS.h>
#include <Resources.h>
#include <Roster.h>
#include <String.h>
#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;
}