Re: Test Cases + Nib files

  • Hello,

    I am writing a game in which I am creating some custom view classes
    and I want to create test cases where I verify that the behavior of
    these classes is "as advertised."

    Is there a way to add nib files to a test case bundle? Or do I need to
    create a new target? I created a new target, then a nib file that I
    added to that target, but I get the following message when I build+run
    it: "Error from Debugger: No executable file specified."

    When I go into the Build/Release directory I find a bundle
    "MatrixTestTarget" (the same name as my new target) but it will not
    run (it has the circle with the line through it on the icon). Inside
    the bundle there is no MacOS directory or executable anywhere.

    Thanks in advance. I can't find any documentation on this stuff so I'm
    blindly stabbing into the dark right now.

    Jacob Portukalian
    Student: Math / Electrical Engineering
    Pasadena City College
    Pasadena, CA 91106
    (626) 679 - 5421

    On Nov 12, 2007, at 12:05 PM, <cocoa-dev-request...> wrote:

    > Send Cocoa-dev mailing list submissions to
    > <cocoa-dev...>
    >
    > To subscribe or unsubscribe via the World Wide Web, visit
    > http://lists.apple.com/mailman/listinfo/cocoa-dev
    > or, via email, send a message with subject or body 'help' to
    > <cocoa-dev-request...>
    >
    > You can reach the person managing the list at
    > <cocoa-dev-owner...>
    >
    > When replying, please edit your Subject line so it is more specific
    > than "Re: Contents of Cocoa-dev digest..."
    >
    >
    > Today's Topics:
    >
    > 1. Re: Crash Reporter for Cocoa Application (Scott Ribe)
    > 2. Re: Crash Reporter for Cocoa Application (John Stiles)
    > 3. Re: How to archive structs like NSRect (Gordon Apple)
    > 4. Re: Adding subviews to a PDFView (Antonio Nunes)
    > 5. Re: Notification when switching Spaces? (Christopher Hickman)
    > 6. Re: Notification when switching Spaces? (Thomas Davie)
    > 7. Re: How to implement an open dialog in a sheet and process
    > its    output? (Nathaniel Gottlieb-Graham)
    > 8. NSCoder blues (was Re: How to archive structs like NSRect)
    > (David Spooner)
    >
    >
    > ----------------------------------------------------------------------
    >
    > Message: 1
    > Date: Mon, 12 Nov 2007 11:03:34 -0700
    > From: Scott Ribe <scott_ribe...>
    > Subject: Re: Crash Reporter for Cocoa Application
    > To: John Stiles <JStiles...>
    > Cc: <cocoa-dev...>
    > Message-ID: <C35DE386.857E1%<scott_ribe...>
    > Content-Type: text/plain;    charset="US-ASCII"
    >
    >> There's no trick here. Just use Launch Services or NSWorkspace -
    >> openFile: to launch the helper app, and it will be a child of the
    >> window server. This has always been the right way to launch GUI app.
    >> Fork/exec leave the app as a child of your app, causing lots of minor
    >> issues.
    >
    > I didn't know Launch Services would do that. I suppose it should
    > have been
    > obvious, but...
    >
    > Anyway, I used NSTask. Until (around 10.4.10) it stopped working
    > with a
    > mysterious error message on some Macs but not others. I switched to
    > vfork/exec. But I only to launch a script which calls launchctl and
    > then
    > returns--so there is no process left as a child of my app.
    >
    > I'll look at the other options next time I update anything about this.
    >
    > --
    > Scott Ribe
    > <scott_ribe...>
    > http://www.killerbytes.com/
    > (303) 722-0567 voice
    >
    >
    >
    >
    > ------------------------------
    >
    > Message: 2
    > Date: Mon, 12 Nov 2007 10:07:23 -0800
    > From: John Stiles <JStiles...>
    > Subject: Re: Crash Reporter for Cocoa Application
    > To: Scott Ribe <scott_ribe...>
    > Cc: <cocoa-dev...>
    > Message-ID: <D5EC9BC5-51CD-4BE0-9621-2DA50AD8BA05...>
    > Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
    >
    > Yeah, you are going the long way around here. NSWorkspace -openFile:
    > is a one liner and will get rid of a lot of extra hassle for you.
    >
    >
    > On Nov 12, 2007, at 10:03 AM, Scott Ribe wrote:
    >
    >>> There's no trick here. Just use Launch Services or NSWorkspace -
    >>> openFile: to launch the helper app, and it will be a child of the
    >>> window server. This has always been the right way to launch GUI app.
    >>> Fork/exec leave the app as a child of your app, causing lots of
    >>> minor
    >>> issues.
    >>
    >> I didn't know Launch Services would do that. I suppose it should
    >> have been
    >> obvious, but...
    >>
    >> Anyway, I used NSTask. Until (around 10.4.10) it stopped working
    >> with a
    >> mysterious error message on some Macs but not others. I switched to
    >> vfork/exec. But I only to launch a script which calls launchctl and
    >> then
    >> returns--so there is no process left as a child of my app.
    >>
    >> I'll look at the other options next time I update anything about
    >> this.
    >>
    >> --
    >> Scott Ribe
    >> <scott_ribe...>
    >> http://www.killerbytes.com/
    >> (303) 722-0567 voice
    >>
    >>
    >
    >
    >
    > ------------------------------
    >
    > Message: 3
    > Date: Mon, 12 Nov 2007 12:16:25 -0600
    > From: Gordon Apple <ga...>
    > Subject: Re: How to archive structs like NSRect
    > To: <cocoa-dev...>
    > Message-ID: <C35DF499.7AD15%<ga...>
    > Content-Type: text/plain; charset="US-ASCII"
    >
    > That doesn't work.  NSKeyedArchiver chokes on it.  That's
    > currently high
    > on my gripe list.  I resorted to class-testing and wrapping NSValues
    > in
    > NSData, although I may change to the string approach for rects.  I am
    > thankful that you can now at least archive NSColor with a keyed
    > archiver.  I
    > wish they would include NSValues.  IMHO, if you can put it into an
    > array or
    > a dictionary, you should be able to archive it.
    >
    > BTW, if you take my approach of class-testing be sure and use
    > "isKindOf", not "isMemberOf", because NSValue is not just a class --
    > it is a
    > class cluster. (Found this out the hard way).
    >
    >> Message: 3
    >> Date: Mon, 12 Nov 2007 09:27:33 -0500
    >> From: Hank Heijink <hank.list...>
    >> Subject: Re: How to archive structs like NSRect
    >> To: Andrew Ebling <aebling...>
    >> Cc: "<cocoa-dev...>" <cocoa-dev...>
    >> Message-ID: <7E41D32C-F354-4629-90F3-AE7149BE838E...>
    >> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
    >>
    >> You can wrap an NSRect in an NSValue, but I just use NSRectToString
    >> and NSStringToRect to make it an object.
    >>
    >> Hope that helps,
    >> Hank
    >>
    >> On Nov 12, 2007, at 9:12 AM, Andrew Ebling wrote:
    >
    >
    >
    > ------------------------------
    >
    > Message: 4
    > Date: Mon, 12 Nov 2007 18:21:39 +0000
    > From: Antonio Nunes <devlists...>
    > Subject: Re: Adding subviews to a PDFView
    > To: Joel Norvell <frameworker...>
    > Cc: <cocoa-dev...>
    > Message-ID: <65779749-A9EF-4453-B89B-DDCCA253A0D3...>
    > Content-Type: text/plain; charset=WINDOWS-1252; format=flowed;
    > delsp=yes
    >
    > On 12 Nov 2007, at 17:46, Joel Norvell wrote:
    >
    >> There is a (10.5) sample program called PDFView Subclasser that
    >> “shows you how
    >> to subclass PDFView in order to overlay content relative to the PDF
    >> content.”
    >> It uses a new 10.5 PDFView method drawPagePost.
    >>
    >> That may help you do what you need to do.
    >
    > <embarrassed-blush-on-cheeks>Duh, I know that example. What was I
    > thinking?! At any rate I was not remembering to look for anything in
    > the example project. I'll play around with this. Should get me
    > there.</
    > embarrassed-blush-on-cheeks>
    >
    > Thanks,
    > Antonio
    >
    > --------------------------------------------------------
    > Today you are You, that is truer than true.
    > There is no one alive who is Youer than You.
    > Today I am Me, and I am freer than free.
    > There is no one alive who is Me-er than Me.
    > I am the BEST I can possibly be.
    >
    > --Dr. Seuss
    > --------------------------------------------------------
    >
    >
    >
    >
    > ------------------------------
    >
    > Message: 5
    > Date: Mon, 12 Nov 2007 13:27:18 -0500
    > From: Christopher Hickman <tophu...>
    > Subject: Re: Notification when switching Spaces?
    > Cc: Cocoa-Dev Mail <cocoa-dev...>
    > Message-ID: <DB3E66EA-4AD9-4061-A88B-396CEE400F47...>
    > Content-Type: text/plain;    charset=US-ASCII;    delsp=yes;    format=flowed
    >
    > On Nov 11, 2007, at 2:01 AM, Eric Schlegel wrote:
    >
    >> In general, we prefer to use data-driven approaches, where you tell
    >> us in advance what you want to do when a space switch happens
    >> ("move this window to the active space", for example), and we take
    >> care of doing it for you. That allows us to keep the space switch
    >> animation fast and fluid, and also allows us to change the space
    >> switch behavior in future releases while still keeping
    >> compatibility with what your app requested.
    >
    > Okay, so that explains why there is no notification.  Now can you
    > explain why there is no API to actually switch spaces?
    >
    > ------------------------------
    >
    > Message: 6
    > Date: Mon, 12 Nov 2007 18:32:23 +0000
    > From: Thomas Davie <tom.davie...>
    > Subject: Re: Notification when switching Spaces?
    > To: Christopher Hickman <tophu...>
    > Cc: Cocoa-Dev Mail <cocoa-dev...>
    > Message-ID: <DB665F33-96AE-4FE0-969A-72C3C49E8C6D...>
    > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
    >
    > On 12 Nov 2007, at 18:27, Christopher Hickman wrote:
    >
    >> On Nov 11, 2007, at 2:01 AM, Eric Schlegel wrote:
    >>
    >>> In general, we prefer to use data-driven approaches, where you tell
    >>> us in advance what you want to do when a space switch happens
    >>> ("move this window to the active space", for example), and we take
    >>> care of doing it for you. That allows us to keep the space switch
    >>> animation fast and fluid, and also allows us to change the space
    >>> switch behavior in future releases while still keeping
    >>> compatibility with what your app requested.
    >>
    >> Okay, so that explains why there is no notification.  Now can you
    >> explain why there is no API to actually switch spaces?
    >
    > Probably a case of applications switching spaces for users would get
    > incredibly annoying when they started doing things the user didn't
    > want to happen.
    >
    > Bob
    >
    >
    > ------------------------------
    >
    > Message: 7
    > Date: Mon, 12 Nov 2007 14:30:24 -0500
    > From: Nathaniel Gottlieb-Graham <sladuuch...>
    > Subject: Re: How to implement an open dialog in a sheet and process
    > its    output?
    > To: <cocoa-dev...>
    > Message-ID: <BF69B7C7-99BD-463A-9272-4343E6F365CE...>
    > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
    >
    > Thanks Ron, that was a great help.  I now have the following code in
    > the .m file, but nothing happens when the button I've wired up to this
    > is clicked on.  I know the method is getting called, but the sheet
    > never appears.
    >
    >
    > - (IBAction)askForQuickTimeMovieSheet:(id)sender {
    >
    > NSOpenPanel *panel = [NSOpenPanel openPanel];
    > NSArray *fileTypes = [NSArray arrayWithObjects:@"mov", @"mp4",
    > @"avi", nil];
    >
    > [panel beginSheetForDirectory:@"~Movies/"
    > file:nil
    > types:fileTypes
    > modalForWindow:[welcomeWindow window]
    > modalDelegate:self
    > didEndSelector:@selector(filePanelDidEnd:
    > returnCode:
    > contextInfo:)
    > contextInfo:nil];
    > }
    >
    > -(void)filePanelDidEnd:(NSOpenPanel*)sheet
    > returnCode:(int)returnCode
    > contextInfo:(void*)contextInfo {
    > // Do stuff here as soon as the sheet displays properly
    > }
    >
    > Thanks again,
    > Nathaniel
    >
    >
    >> Hi Nathaniel,
    >>
    >> you're right, it is easy.
    >>
    >> First step, look at the documentation for NSOpenPanel.  You'll see
    >> the instance method
    >> beginSheetForDirectory:file:types:modalForWindow:modalDelegate:didEndSelector:contextInfo
    >> :.  Because it's an instance method, you first create an instance of
    >> NSOpenPanel using the class method + (NSOpenPanel *)openPanel,
    >> which, as the documentation states, creates and returns an
    >> NSOpenPanel instance.  For example,
    >>
    >> NSOpenPanel *myOpenPanel = [NSOpenPanel openPanel];
    >>
    >> So now configure your open panel however you like.  Look at the
    >> documentation to find out how.
    >>
    >> Then, note the instance method -filenames.  Using what you get in
    >> the filenames NSArray, feed your QTMovieView with whatever it needs
    >> to play the movie.
    >>
    >>
    >> If you need more of an explanation, read the topics referenced at
    >> the top of the NSOpenPanel Class reference document, namely,
    >> "Application File Management" and "Sheet Programming Topics for
    >> Cocoa".  The second one is probably what you want to read.
    >>
    >>
    >> Hope this helps,
    >>
    >> Ron
    >>
    >> PS.  If you don't already have it, I'd recommend Aaron Hillegass'
    >> excellent "Cocoa Programming For Mac OS X" book.
    >
    >
    > ---------------------------------
    > Nathaniel Gottlieb-Graham
    > Mac specialist
    > <sladuuch...>
    > techpaladin.com
    >
    >
    >
    > ------------------------------
    >
    > Message: 8
    > Date: Mon, 12 Nov 2007 12:55:02 -0700
    > From: David Spooner <dave...>
    > Subject: NSCoder blues (was Re: How to archive structs like NSRect)
    > To: "Cocoa-Dev (Apple)" <cocoa-dev...>
    > Message-ID: <16C6C16B-0E67-4B34-99C7-703380B357B5...>
    > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
    >
    >
    > I would like to take this opportunity to (respectfully) express my
    > concerns about the apparent rift in the NSCoder classes.
    >
    > It would seem that NSArchiver is being deprecated since newer classes
    > such as NSIndexPath do not implement non-keyed coding and (as Doug
    > Knowles pointed out) NSPredicate no longer supports non-keyed coding
    > in 10.5.  I think NSKeyedArchiver was a significant step forward in
    > dealing with legacy coding issues, but there are two significant
    > problems :
    >
    > 1) NSPortCoder does not support keyed coding
    >
    > 2) NSKeyedArchiver does not provide the same level of support for
    > non-object types as NSArchiver does
    >
    > I suspect the problem which Gordon has observed with NSValue is a
    > consequence of 2, since presumably NSValue's -encodeWithCoder: uses -
    > encodeValueOfObjCType:at:.
    >
    > As another example of why 2 is a problem, suppose I have a triangle
    > mesh object with vertices represented as a c-array of struct {float x,
    > y, z;}.  With an NSArchiver I could encode the vertex array using
    > either -encodeArrayOfObjCType:count:at: or -
    > encodeValueOfObjCType:at:.  An NSKeyedArchiver throws an exception
    > when using the non-keyed methods in this situation (although it does
    > work for simpler c-types such as an array of floats).
    >
    > I realize that I could encode the vertices as NSData, but in order to
    > be architecture independent I would have to first use NSArchiver to
    > create the NSData and then encode the data using -encodeObject:forKey:
    > -- an arguably unnecessary copy.  It would be far preferable to have
    > a
    > keyed-coding method -encodeValueOfObjCType:forKey:at: which provides
    > the functionality which I have come to expect from NSArchiver.
    >
    > I have filed an enhancement request (5163604) to this effect...
    >
    > Cheers,
    > dave
    >
    >
    > On 12-Nov-07, at 11:16 AM, Gordon Apple wrote:
    >
    >> That doesn't work.  NSKeyedArchiver chokes on it.  That's
    >> currently high
    >> on my gripe list.  I resorted to class-testing and wrapping NSValues
    >> in
    >> NSData, although I may change to the string approach for rects.  I am
    >> thankful that you can now at least archive NSColor with a keyed
    >> archiver.  I
    >> wish they would include NSValues.  IMHO, if you can put it into an
    >> array or
    >> a dictionary, you should be able to archive it.
    >>
    >> BTW, if you take my approach of class-testing be sure and use
    >> "isKindOf", not "isMemberOf", because NSValue is not just a class --
    >> it is a
    >> class cluster. (Found this out the hard way).
    >>
    >>> Message: 3
    >>> Date: Mon, 12 Nov 2007 09:27:33 -0500
    >>> From: Hank Heijink <hank.list...>
    >>> Subject: Re: How to archive structs like NSRect
    >>> To: Andrew Ebling <aebling...>
    >>> Cc: "<cocoa-dev...>" <cocoa-dev...>
    >>> Message-ID: <7E41D32C-F354-4629-90F3-AE7149BE838E...>
    >>> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
    >>>
    >>> You can wrap an NSRect in an NSValue, but I just use NSRectToString
    >>> and NSStringToRect to make it an object.
    >>>
    >>> Hope that helps,
    >>> Hank
    >>>
    >>> On Nov 12, 2007, at 9:12 AM, Andrew Ebling wrote:
    >>
    >
    >
    > ------------------------------
    >
    > _______________________________________________
    >
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    >
    > Do not post admin requests or moderator comments to the list.
    > Contact the moderators at cocoa-dev-admins (at) lists.apple.com
    >
    > http://lists.apple.com/mailman/listinfo/cocoa-dev
    >
    >
    > End of Cocoa-dev Digest, Vol 4, Issue 1157
    > ******************************************
  • On Nov 13, 2007, at 10:03 AM, Jacob Portukalian wrote:

    > I am writing a game in which I am creating some custom view classes
    > and I want to create test cases where I verify that the behavior of
    > these classes is "as advertised."

    First off, it'll be helpful to tell us what version of Mac OS X and
    what version of Xcode you're using.  It matters.

    > Is there a way to add nib files to a test case bundle? Or do I need
    > to create a new target? I created a new target, then a nib file that
    > I added to that target, but I get the following message when I build
    > +run it: "Error from Debugger: No executable file specified."

    You can just add your nib files as members of your test bundle.  When
    you load them, of course, you'll want to load them from the test
    bundle's resources rather than from the main bundle's resources.

    For example, you can very easily write a test case like the following,
    and test a nib whose File's Owner is an instance of NSViewController:

    // MyTestCase.h
    #import <Cocoa/Cocoa.h>
    #import <SenTestingKit/SenTestingKit.h>

    @interface MyTestCase : SenTestCase {
    @private
        NSViewController *viewController;
        NSView *view;
    }
    @end

    // MyTestCase.m
    #import "MyTestCase.h"

    @implementation MyTestCase

    - (void)setUp {
        [super setUp];

        viewController = [[NSViewController alloc]
    initWithNibName:@"MyTestNib" bundle:[NSBundle bundleForClass:[self
    class]]];
        view = [viewController view]; // owned by viewController
    }

    - (void)tearDown {
        [viewController release];
        view = nil; // owned by viewController

        [super tearDown];
    }

    - (void)testInstantiation {
        STAssertNotNil(viewController, @"Should be able to instantiate
    the view controller with the nib 'MyTestNib' in the test bundle.");
    }

    @end

    > When I go into the Build/Release directory I find a bundle
    > "MatrixTestTarget" (the same name as my new target) but it will not
    > run (it has the circle with the line through it on the icon). Inside
    > the bundle there is no MacOS directory or executable anywhere.

    Have you actually written any unit test code that is part of that
    bundle?

    I've written a series of weblog posts on using Xcode's unit testing
    infrastructure that can be found here:

      Chris Hanson tags: unit testing
      http://chanson.livejournal.com/tag/unit+testing

    I still need to post updated versions of the Debugging Cocoa Framework
    Unit Tests and Debugging Cocoa Application Unit Tests articles, since
    you need to add a couple of additional environment variables to debug
    them.  And to cover running tests for frameworks that require
    Objective-C garbage collection.

    > Thanks in advance. I can't find any documentation on this stuff so
    > I'm blindly stabbing into the dark right now.

    Xcode 2.1 and later do include a Unit Testing Guide which my weblog
    posts supplement.

      -- Chris
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today