TweetFollow Us on Twitter

May 93 - Testing Custom Resources for Errors

Testing Custom Resources for Errors

Steve Lavagnino & Laurie Seaton

The use of custom resources provides unique ways of handling information on the Macintosh. It also poses some interesting problems. One such problem is how to automate testing of custom resources for spelling errors, validity, and adherence to user interface guidelines.

Our product, SoftPolish, was originally developed to automate the testing of standard user interface resources. We included hundreds of tests on almost all the standard resources. However, we knew the importance of anticipating demands from our user community; especially from our target market, detail-oriented software professionals. They would discover both new resources to test and new tests to make on existing resources. To keep these users happy, we needed to enable SoftPolish to check any custom resource. Simultaneously we wanted to provide an easy way to update our product to test new resource types and to enhance existing tests. The following describes how we achieved those goals.

Customizing SoftPolish™ to Handle Custom Resource Types

SoftPolish Code Modules

SoftPolish can be customized through the use of external code modules, which supplement or replace built-in resource tests. As SoftPolish scans a target file, target resources are loaded into memory and examined. SoftPolish checks its own resource fork to see if an external code module exists for the target resource type.

If a match occurs, a parameter block is constructed and passed to the external code module. The parameter block includes the address in memory of the target resource, the resource tests which were specified in the user's Scan dialog (See Figure 1. SoftPolish Scan Dialog), and fields that allow an external code module to request services from SoftPolish such as spell-checking or error-reporting.

What to Test

The general programming style for code modules is to have them first check the parameter block to see which tests are currently requested. Not all tests may be chosen, or selected tests may not be relevant to the resource the module is checking. In Listing 1, the routine STR checks to see if the user has chosen UserInterface, Spelling, or listStrings options. After determining that one of these options has been chosen, STR extracts the string from the resource. (For a custom resource it may well be a more complicated routine that extracts strings or other information from within the resource.)

Communicating with SoftPolish

After the string is extracted in Listing 1, a series of assignments sets fields in the parameter block. The first assignment sets the pleasedo field to msgDoString. The pleasedo field is defined by using a set of predefined constants or parameters located in the header files of the example source code. These predefined constants all start with 'msg' and each constant correlates to an action in SoftPolish. Before a callback is made, the code module must set the pleasedo field to an 'msg' constant which specifies the desired action. Pleasedo is an important field in the parameter block because it tells SoftPolish what to do when a callback is made. Actions that SoftPolish can make via callbacks are: testing to determine if a referenced resource is of the proper size, testing to see if a string can be displayed within a specified rectangle, spell-checking strings, replacing strings, writing the changed strings to the resource, displaying the progress of checks to SoftPolish, and reporting error messages to the SoftPolish log file. In Listing 1, the predefined constant msgDoString tells SoftPolish it is receiving a string to test.

Depending on what the desired action is, additional data about the resource is usually required before the callback can be made. For instance, msgDoString in Listing 1 requires several other assignments: a pointer to the text you want checked is put in the field textPtr, the length of the text is put into textLen, and then options (such as checks for capitalization and quote checking) are set with booleans in fields arg.aDoString.bePicky and arg.aDoString.initialCaps. The last assignment to arg.aDoString.spellit utilizes one of the user options already in the parameter block to establish whether a callback string should be checked.

Now that all the parameter block fields are set, the code module makes a callback to the SoftPolish application by calling the procedure DoCallBack. DoCallBack takes the callbackaddress field in the parameter block as its argument. Even if a module is doing its own testing of resources, it uses callbacks to report errors to the standard SoftPolish log file.

Naming the Code Module

Once the routine for handling the resource is written, you need to give the code resource a name and type. Each code module must have a resource of type 'SPCM' (SoftPolish Code Module) or 'SPSM' (Softpolish Supplemental Module). The resource name of the code module indicates what type of resource the code module accepts. For example, an 'SPCM' resource named 'STR ' is, to SoftPolish, a code module that handles 'STR ' resources. If you add an 'SPCM' module for a type SoftPolish already tests, your code module will replace the internal SoftPolish handling of that resource type. Alternatively if you add an 'SPSM' code module, your code module supplements the checking done by SoftPolish or an 'SPCM' module for that resource type.

Where to get more information

For more details on other callback routines, check the FrameWorks source code disk or download our technical note on code modules from Applelink or America Online. The note contains examples of code modules in C, Pascal, and FORTRAN. It also provides header files with definitions of ModuleParms, 'msg' constants, and other records that need to be included in your code module.

Listing 1

STR(ModuleParms *MP) { 
Ptr         sptr; 
Str255      str;
/* Determine what to test */
if (MP->Req->doUserInterface || MP->Req->doSpelling 
        || MP->Req->listStrings) {    
    /* Extract the string out of the resource. */
    sptr = *(MP->thdl); 
    memcpy(str,sptr,256);               
    /* Set up the callback for SoftPolish to check the string */
    MP->pleasedo = msgDoString;
    MP->textPtr = &str+1;
    MP->textLen = str[0];
    MP->resItem = -4;
    MP->arg.aDoString.bePicky = true;  
    MP->arg.aDoString.initialCaps = false;       
    MP->arg.aDoString.spellit = MP->Req->doStrings;
    DoCallback(MP->callbackaddress);         
    /* Make changes to the string if necessary */
    if (MP->correctString[0]>0) {     
        SetHandleSize(MP->thdl,MP->correctString[0]+1);
        sptr = *(MP->thdl);      
        memcpy(sptr,MP->correctString,MP->correctString[0]+1);
        MP->pleasedo = msgWriteChangedResource;
        DoCallback(MP->callbackaddress);         
        } 
    }
/* If requested, check the size of the resource */ 
if (MP->Req->doValidity && MP->Req->doSizeCheck) {
    sptr = *(MP->thdl);  
    memcpy(str,sptr,256);               
    MP->pleasedo = msgCheckResourceSize;
    MP->arg.aCheckResourceSize.correctSize = str[0]+1;
    DoCallback(MP->callbackaddress);     
    } 
}
 
AAPL
$119.00
Apple Inc.
+1.40
MSFT
$47.75
Microsoft Corpora
+0.28
GOOG
$540.37
Google Inc.
-0.71

MacTech Search:
Community Search:

Software Updates via MacUpdate

Skype 7.2.0.412 - Voice-over-internet ph...
Skype allows you to talk to friends, family and co-workers across the Internet without the inconvenience of long distance telephone charges. Using peer-to-peer data transmission technology, Skype... Read more
HoudahSpot 3.9.6 - Advanced file search...
HoudahSpot is a powerful file search tool built upon MacOS X Spotlight. Spotlight unleashed Create detailed queries to locate the exact file you need Narrow down searches. Zero in on files Save... Read more
RapidWeaver 6.0.3 - Create template-base...
RapidWeaver is a next-generation Web design application to help you easily create professional-looking Web sites in minutes. No knowledge of complex code is required, RapidWeaver will take care of... Read more
iPhoto Library Manager 4.1.10 - Manage m...
iPhoto Library Manager lets you organize your photos into multiple iPhoto libraries. Separate your high school and college photos from your latest summer vacation pictures. Or keep some photo... Read more
iExplorer 3.5.1.9 - View and transfer al...
iExplorer is an iPhone browser for Mac lets you view the files on your iOS device. By using a drag and drop interface, you can quickly copy files and folders between your Mac and your iPhone or... Read more
MacUpdate Desktop 6.0.3 - Discover and i...
MacUpdate Desktop 6 brings seamless 1-click installs and version updates to your Mac. With a free MacUpdate account and MacUpdate Desktop 6, Mac users can now install almost any Mac app on macupdate.... Read more
SteerMouse 4.2.2 - Powerful third-party...
SteerMouse is an advanced driver for USB and Bluetooth mice. It also supports Apple Mighty Mouse very well. SteerMouse can assign various functions to buttons that Apple's software does not allow,... Read more
iMazing 1.1 - Complete iOS device manage...
iMazing (was DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can: Copy music to and from... Read more
PopChar X 7.0 - Floating window shows av...
PopChar X helps you get the most out of your font collection. With its crystal-clear interface, PopChar X provides a frustration-free way to access any font's special characters. Expanded... Read more
OneNote 15.4 - Free digital notebook fro...
OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that's too important to forget. Whether you're at... Read more

Latest Forum Discussions

See All

Raby (Games)
Raby 1.0.3 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0.3 (iTunes) Description: ***WARNING - Raby runs on: iPhone 5, iPhone 5C, iPhone 5S, iPhone 6, iPhone 6 Plus, iPad Mini Retina, iPad Mini 3, iPad 4, iPad Air,... | Read more »
Oddworld: Stranger's Wrath (Games)
Oddworld: Stranger's Wrath 1.0 Device: iOS Universal Category: Games Price: $5.99, Version: 1.0 (iTunes) Description: ** PLEASE NOTE: Oddworld Stranger's Wrath requires at least an iPhone 4S, iPad 2, iPad Mini or iPod Touch 5th gen... | Read more »
Bounce On Back (Games)
Bounce On Back 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: | Read more »
Make Way for Fat Chicken, from the Maker...
Make Way for Fat Chicken, from the Makers of Scrap Squad Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Relevant Games has announced they will be releasing their reverse tower defense game, | Read more »
Tripnary Review
Tripnary Review By Jennifer Allen on November 26th, 2014 Our Rating: :: TRAVEL BUCKET LISTiPhone App - Designed for the iPhone, compatible with the iPad Want to create a travel bucket list? Tripnary is a fun way to do exactly that... | Read more »
Ossian Studios’ RPG, The Shadow Sun, is...
Ossian Studios’ RPG, The Shadow Sun, is Now Available for $4.99 Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Mmmm, Tasty – Having the Angry Birds for...
The very first Angry Birds debuted on iOS back in 2009. When you sit back and tally up the number of Angry Birds games out there and the impact they’ve had on pop culture as a whole, you just need to ask yourself: “How would the birds taste... | Read more »
Rescue Quest Review
Rescue Quest Review By Jennifer Allen on November 26th, 2014 Our Rating: :: PATH BASED MATCH-3Universal App - Designed for iPhone and iPad Guide a wizard to safety by matching gems. Rescue Quest might not be an entirely original... | Read more »
You Can Play the Final Chapter of Lone W...
You Can Play the Final Chapter of Lone Wolf: Dawn Over V’taag Right Now Posted by Jessica Fisher on November 26th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Swords of Anima (Games)
Swords of Anima 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: A new tactical turn-based RPG experience. Command the Savior Rex Squad in an epic journey of courage and deception. Can you... | Read more »

Price Scanner via MacPrices.net

Black Friday: $300 off 15-inch Retina MacBook...
 B&H Photo has the new 2014 15″ Retina MacBook Pros on sale for $300 off MSRP as part of their Black Friday sale. Shipping is free, and B&H charges NY sales tax only: - 15″ 2.2GHz Retina... Read more
2014 1.4GHz Mac mini on sale for $449, save $...
 B&H Photo has the new 1.4GHz Mac mini on sale for $449.99 including free shipping plus NY tax only. Their price is $50 off MSRP, and it’s the lowest price available for this new model. Adorama... Read more
Early Black Friday pricing on 27-inch 5K iMac...
 B&H Photo continues to offer Black Friday sale prices on the 27″ 3.5GHz 5K iMac, in stock today and on sale for $2299 including free shipping plus NY sales tax only. Their price is $200 off MSRP... Read more
Early Black Friday sale prices on iPad Air 2,...
 MacMall is discounting iPad Air 2s by up to $75 off MSRP as part of their Black Friday sale. Shipping is free: - 16GB iPad Air WiFi: $459 $40 off - 64GB iPad Air WiFi: $559 $40 off - 128GB iPad Air... Read more
Early Black Friday MacBook Air sale prices, $...
 MacMall has posted early Black Friday MacBook Air sale prices. Save $101 on all models for a limited time: - 11″ 1.4GHz/128GB MacBook Air: $798 - 11″ 1.4GHz/256GB MacBook Air: $998 - 13″ 1.4GHz/... Read more
Why iPhone 6 Tablet/Laptop Cannibalization Is...
247wallst.com blogger Douglas A. McIntyre noted last week that according to research posted on the Applovin blog site the iPhone 6 is outselling the iPhone 6 Plus by a wide margin . Hardly a surprise... Read more
Worldwide Tablet Growth Expected to Slow to 7...
The global tablet market is expected to record massive deceleration in 2014 with year-over-year growth slowing to 7.2%, down from 52.5% in 2013, according to a new forecast from International Data... Read more
Touchscreen Glove Company Announces New Produ...
Surrey, United Kingdom based TouchAbility specializes in design and manufacture of a wide variety of products compatible with touchscreen devices including smartphones, tablets and computers. Their... Read more
OtterBox Alpha Glass Screen Protectors for iP...
To complement the bigger, sharper displays on the latest Apple devices, OtterBox has introduced Alpha Glass screen protectors to the iPhone 6 and iPhone 6 Plus. The fortified glass screen protectors... Read more
Early Black Friday Mac Pro sale, 6-Core 3.5GH...
 B&H Photo has the 6-Core 3.5GHz Mac Pro on sale today for $3499 including free shipping plus NY sales tax. Their price is $500 off MSRP, and it’s the lowest price available for this model from... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.