George V. Reilly's Technical Blog

March 2007 - Posts

Hotkey for Clipboard.NET

https://files.bountysource.com/system/files/LibraryEntry/144/screenshot.jpg.medium.jpg

I use Clipboard.NET as a clipboard manager on Windows. It stores the last few entries sent to the clipboard.

There's one problem: the default hotkey is Ctrl+Comma, which also happens to be an important key for Outlook (previous message). I figured out a while ago how to change the hotkey, but my report doesn't show up when you search for it.

Net: using a key name from the ConsoleKey table, change the value of ShortcutKey in %ProgramFiles%\Tom Medhurst\Clipboard.NET\clipmon32.exe.config:

 <applicationSettings>
<clipmon32.Properties.Settings>
<setting name="ShortcutKey" serializeAs="String">
<value>OemComma</value>

The new hotkey will be Ctrl+keyname.

NUnit calling CppUnit

http://www.georgevreilly.com/blog/content/binary/NUnit-CppUnit.png

Over the last few days, I've been adapting an existing native C++ library so that it can be called from managed code. I had written a large number of unit tests with CppUnit and I wanted to be able to call the tests from NUnit.

I suppose that I could have written a new CppUnit TestRunner so that I could call it from NUnit. Instead, I took the cheap-n-dirty route, playing with #define and include paths. It took less time to get working than it did to write this blog post.

Here's the original native CppUnit test code

 //-------------------------------
 // native\FooTest.h
 //-------------------------------

 #include <cppunit/extensions/HelperMacros.h>

 class FooTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( FooTest );
CPPUNIT_TEST( testAlpha );
CPPUNIT_TEST_SUITE_END();
public:
void testAlpha();
};

//------------------------------- // native\FooTest.cpp //------------------------------- #include "FooTest.h" // Registers the fixture into the test 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( FooTest ); void FooTest::testAlpha()
{
CPPUNIT_ASSERT( 4 == 2 + 2);
}

And here's my managed NUnit-based wrapper.

 //-------------------------------
 // managed\FooTest.h
 //-------------------------------

 using namespace NUnit::Framework;

// Gross hack. Define a completely different NUnit-compatible FooTest // test fixture and use #define's to make the CPPUnit-specific // stuff build. [TestFixture] public ref class FooTest
{
public:
[Test] void testAlpha();
};

#define CPPUNIT_TEST_SUITE_REGISTRATION(x) #define CPPUNIT_ASSERT(x) Assert::IsTrue(x)

I had to make one change to native\FooTest.cpp, to #include <FooTest.h> (angle brackets). This picks up the first FooTest.h in the include path, so that the managed version of FooTest.cpp now picks up managed\FooTest.h, instead of the original.

Posted: Mar 21 2007, 12:12 PM by george_v_reilly | with 2 comment(s)
Filed under:
NVelocity: loading templates from embedded resources

http://www.codegeneration.net/logos/nvelocity.gif

In last week's tip on using the NVelocity template formatting engine, I described what to set to load a template from an absolute path.

Here's the magic necessary to get NVelocity to load a template from an embedded resource:

 VelocityEngine engine = new VelocityEngine();
ExtendedProperties properties = new ExtendedProperties();
properties.AddProperty("resource.loader", "assembly");
properties.AddProperty("assembly.resource.loader.class",
"NVelocity.Runtime.Resource.Loader.AssemblyResourceLoader, NVelocity");
properties.AddProperty("assembly.resource.loader.assembly", "StencilFormatter");
engine.Init(properties);
Posted: Mar 14 2007, 10:50 AM by george_v_reilly | with 3 comment(s)
Filed under:
NVelocity templates and absolute paths

http://www.codegeneration.net/logos/nvelocity.gif

We've started using the NVelocity template formatting engine. We were absolutely stymied for an hour, trying to figure out how to get it working with an absolute path to the template file, instead of the relative path shown in the documentation.

The trick is to set file.resource.loader.path. Here's how to load C:\foo\bar\somefile.vm:

 ExtendedProperties props = new ExtendedProperties();
props.AddProperty("file.resource.loader.path", new ArrayList(new string[]{".", "C:\\"}));
velocity.Init(props);

template = velocity.GetTemplate("foo\\bar\\somefile.vm");
Posted: Mar 06 2007, 05:09 PM by george_v_reilly | with 13 comment(s)
Filed under:
More Posts