From 98bad22a2b68bc559864ca69327e8c72bce4f15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 4 Jul 2006 09:40:49 +0000 Subject: [PATCH] * fixes build... completely forgot about this one :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18023 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../app/archived_view/ArchivedView.rdef | 5 + src/tests/servers/app/archived_view/Jamfile | 18 ++ src/tests/servers/app/archived_view/main.cpp | 187 ++++++++++++++++++ src/tests/servers/app/archived_view/run | 17 ++ 4 files changed, 227 insertions(+) create mode 100644 src/tests/servers/app/archived_view/ArchivedView.rdef create mode 100644 src/tests/servers/app/archived_view/Jamfile create mode 100644 src/tests/servers/app/archived_view/main.cpp create mode 100755 src/tests/servers/app/archived_view/run diff --git a/src/tests/servers/app/archived_view/ArchivedView.rdef b/src/tests/servers/app/archived_view/ArchivedView.rdef new file mode 100644 index 0000000000..98f33456b8 --- /dev/null +++ b/src/tests/servers/app/archived_view/ArchivedView.rdef @@ -0,0 +1,5 @@ + +resource(1, "BEOS:APP_FLAGS") #'APPF' $"00000000"; + +resource(1, "BEOS:APP_SIG") #'MIMS' "application/x.vnd-Haiku.ArchivedView"; + diff --git a/src/tests/servers/app/archived_view/Jamfile b/src/tests/servers/app/archived_view/Jamfile new file mode 100644 index 0000000000..27c79f043a --- /dev/null +++ b/src/tests/servers/app/archived_view/Jamfile @@ -0,0 +1,18 @@ +SubDir HAIKU_TOP src tests servers app archived_view ; + +SetSubDirSupportedPlatformsBeOSCompatible ; +AddSubDirSupportedPlatforms libbe_test ; + +UseHeaders [ FDirName os app ] ; +UseHeaders [ FDirName os interface ] ; + +SimpleTest ArchivedView : + main.cpp + : be + : ArchivedView.rdef + ; + +if ( $(TARGET_PLATFORM) = libbe_test ) { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : ArchivedView + : tests!apps ; +} diff --git a/src/tests/servers/app/archived_view/main.cpp b/src/tests/servers/app/archived_view/main.cpp new file mode 100644 index 0000000000..0f3657b56e --- /dev/null +++ b/src/tests/servers/app/archived_view/main.cpp @@ -0,0 +1,187 @@ +// main.cpp + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +static const char* kAppSignature = "application/x.vnd-Haiku.ArchivedView"; + +class TestView : public BView { + + public: + TestView(BRect frame, const char* name, + uint32 resizeFlags, uint32 flags); + + TestView(BMessage* archive); + + virtual status_t Archive(BMessage* into, bool deep = true) const; + + static BArchivable* Instantiate(BMessage* archive); + + virtual void AttachedToWindow(); + virtual void DetachedFromWindow(); + + virtual void Draw(BRect updateRect); + + private: + int32 fData; +}; + + +// constructor +TestView::TestView(BRect frame, const char* name, + uint32 resizeFlags, uint32 flags) + : BView(frame, name, resizeFlags, flags), + fData(42) +{ + SetViewColor(216, 216, 216); + + BRect r = Bounds(); + r.top = r.bottom - 7; + r.left = r.right - 7; + BDragger *dw = new BDragger(r, this, 0); + AddChild(dw); +} + +// constructor +TestView::TestView(BMessage* archive) + : BView(archive) +{ + if (archive->FindInt32("data", &fData) < B_OK) + fData = 5; + + printf("data: %ld\n", fData); +} + +// AttachedToWindow +void +TestView::AttachedToWindow() +{ +} + +// DetachedFromWindow +void +TestView::DetachedFromWindow() +{ + BFile file("/tmp/archived_view", + B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); + status_t err = file.InitCheck(); + if (err != B_OK) { + printf("error creating file for archiving: %s\n", strerror(err)); + return; + } + BMessage archive; + err = Archive(&archive); + if (err != B_OK) { + printf("error archiving: %s\n", strerror(err)); + return; + } + err = archive.Flatten(&file); + if (err != B_OK) { + printf("error flattening: %s\n", strerror(err)); + return; + } +} + +// Draw +void +TestView::Draw(BRect updateRect) +{ +printf("TestView::Draw("); +updateRect.PrintToStream(); + BRect r(Bounds()); + + rgb_color light = tint_color(ViewColor(), B_LIGHTEN_2_TINT); + rgb_color shadow = tint_color(ViewColor(), B_DARKEN_2_TINT); + + BeginLineArray(4); + AddLine(r.LeftTop(), r.RightTop(), light); + AddLine(r.RightTop(), r.RightBottom(), shadow); + AddLine(r.RightBottom(), r.LeftBottom(), shadow); + AddLine(r.LeftBottom(), r.LeftTop(), light); + EndLineArray(); +} + +// Archive +status_t +TestView::Archive(BMessage* into, bool deep = true) const +{ + status_t ret = BView::Archive(into, deep); + + if (ret == B_OK) + ret = into->AddInt32("data", fData); + + if (ret == B_OK) + ret = into->AddString("add_on", kAppSignature); + + if (ret == B_OK) + ret = into->AddString("class", "TestView"); + + return ret; +} + +// Instantiate +BArchivable * +TestView::Instantiate(BMessage* archive) +{ + if (!validate_instantiation(archive , "TestView")) + return NULL; + + return new TestView(archive); +} + +// #pragma mark - + +// show_window +void +show_window(BRect frame, const char* name) +{ + BWindow* window = new BWindow(frame, name, + B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE); + + BView* view = NULL; + BFile file("/tmp/archived_view", B_READ_ONLY); + if (file.InitCheck() == B_OK) { + printf("found archive file\n"); + BMessage archive; + if (archive.Unflatten(&file) == B_OK) { + printf("unflattened archive message\n"); + BArchivable* archivable = instantiate_object(&archive); + view = dynamic_cast(archivable); + if (view) + printf("instatiated BView\n"); + } + } + + if (!view) + view = new TestView(window->Bounds(), "test", B_FOLLOW_ALL, B_WILL_DRAW); + + window->Show(); + + window->Lock(); + window->AddChild(view); + window->Unlock(); +} + +// main +int +main(int argc, char** argv) +{ + BApplication* app = new BApplication(kAppSignature); + + BRect frame(50.0, 50.0, 300.0, 250.0); + show_window(frame, "BView Archiving Test"); + + app->Run(); + + delete app; + return 0; +} diff --git a/src/tests/servers/app/archived_view/run b/src/tests/servers/app/archived_view/run new file mode 100755 index 0000000000..896269e9c3 --- /dev/null +++ b/src/tests/servers/app/archived_view/run @@ -0,0 +1,17 @@ +#!/bin/sh + +../../../../../generated/tests/apps/run_haiku_registrar || exit + +if test -f ../../../../../generated/tests/apps/haiku_app_server; then + ../../../../../generated/tests/apps/haiku_app_server & +else + echo "You need to \"TARGET_PLATFORM=libbe_test jam install-test-apps\" first." +fi + +sleep 1s + +if test -f ../../../../../generated/tests/apps/ArchivedView; then + ../../../../../generated/tests/apps/ArchivedView +else + echo "You need to \"TARGET_PLATFORM=libbe_test jam install-test-apps\" first." +fi