I got a very strange request from one of my customers (at least according to my current knowledge). I have to build an iOS framework, which main purpose is to wrap a C/C++ library with Obj-C code, to hide some of its general API and expose only what my customer want me to expose via Obj-C. Now, here comes the tricky part. This framework is going to be a dependency for an application (objects/methods/functions/whatever should be accessible from , i.e. view controllers) and for another framework. Is it possible to build this framework in a way that expose only part of an API to an application and part of API to another framework which is going to use it internally?
According to my knowledge it is impossible and framework can expose only one API, which is common to every possible consumer/user. However my knowledge might not be complete in this topic.
Additional question: can I expose both Obj-C and C API from a single framework. I assume I can, but just want to make sure.
Please don't ask about rationale behind this idea. This is a requirement I got and have to investigate so I can't provide any sensible justification at the moment.
Thanks!
I'm about to write a program in C++, but I'm unsure as to how to go about it. I want to create a program that can be used with a command line frontend but also a GUI frontend as I don't want to bind a user to a specific interface such as a widget toolkit for dependencies' sake.
How would be the best way to do this? I know some programs like RSync and SSH have frontends in GUIs, but I'm not sure how this is done. Wouldn't it be hacky to have a program that just uses system() to run it all while having a pretty GUI?
You implement your program's algorithms in a library, carefully avoiding any UI stuff. The API to your algorithms is specified in header files.
Then you can write several applications that use this library, one implementing a GUI front end and one a command line interface. They include the headers and compile against the API, and you link the library to it.
Be careful to not to compile the library and the GUI with inconsistent settings.
IME the separation of algorithms from UI can be achieved best when you first implement a command line UI. You might have to employ callbacks for that separation.
Without knowing any other requirements, the simplest answer is just to compile your "backend" as a library, and then link your various "frontends" against it.
More complex answers involve setting your backend up as a daemon/server.
You shouldn't need system-calls to do any of this (unless you have very specific requirements).
You can inspire yourself on the MVC design pattern. The differing front-ends are the views on your model-controller. The controller can be a library which will factor the common tasks of your application. The GUI part and the shell part (or another language integration part for example) all use this "headless" library. Having a clear separation from the start will help enforcing modularity and decoupling.
You could use QT for the GUI front end. But I'd actually just write your library first. Then do your GUI last.
Some helpful advice
Be sure to write unit tests WHILE writing your code.
Be sure to use a code coverage tool to evaluate your unit tests while writing your code.
Be sure to avoid BOOL types since those are usually defined in the platform API (like win32). Use bool instead.
Forward declare as many types as you can in your header files. Include as few as possible header files in each library header file.
Expose as minimal an interface as possible.
Be sure to follow good coding practices for c++. Herb Sutters Book C++ coding standards is excellent in this regard.
Once you do write your gui, put as little business logic in your GUI event handlers as possible. Basically you want your library to be agnostic towards your GUI. Someone else mentioned the MVC pattern here. That is excellent advice.
What is PocoCapsule current status? Is it evolving? Has it been forked
with some other product?
What is about the whole idea of IoC for C++? If PocoCapsule is not
evolving, is it because IoC was considered not useful for C++, unsafe,
other patterns appeared or something else?
As far as I understand there are 2-3, maybe few more products, that
implement IoC for C++, available and
PocoCapsule is the most mature of them.
I see several disadvantages in current version (as I see it's 1.1 from
google code):
No separate namespace.
Header files are required to be right in INCLUDE folder - better to place them in subfolder.
Generation Tools depend on Java.
No static linking libraries are built by default.
Cannot generate source code out of setup.xml for compilation and link with my app if I don't need reconfiguration feature.
Does anybody have the same thoughts? Does anybody work on something of
this list? Are there any barriers to start working, like patents?
I emailed Ke Jin (maintainer) and his response was that it is not under current, active development as of Jul 14, 2011. He did not give a reason.
I have been looking for this myself for some time now, and came realize that there are no good IoC Containers in C++. There are a lot of problems implementing this. Getting something like the C# IoC Containers (Castle Windsor, Unity, etc.) is out of reach. My guess is that if you require something like this, you don´t do c++. And if you do C++, you roll your own or use singleton factories (little joke) ;)
An easy shortcut is to use Qt´s QML. It was build for declarative UIs but can be used for building any QObject based tree.
Another good look are CORBA Systems for C++, they may have some of the things you require.
Just my hints for other places to look...
I think that you can successfully use Qt metaobject system by reusing QtCore library and moc-compiler in your application.
With metaobject system you can create fully isolated modules by calling any method of module's interface via QMetaObject::invokeMethod().
And all will work without QCoreApplication object instance! Define your modules as subclasses of QObject, provide Q_OBJECT macro and mark all interface methods with Q_INVOKABLE ( of course, you should add moc-compiler as build step ).
In C++, there isn't a de-facto standard logging tool. In my experience, shops roll their own. This creates a bit of a problem, however, when trying to create reusable software components. If everything in your system depends on the logging component, this makes the software less reusable, basically forcing any downstream projects to take your logging framework along with the components they really want.
IOC (dependency injection) doesn't really help with the problem since your components would need to depend on a logging abstraction. Logging components themselves can add dependencies on file I/O, triggering mechanisms, and other possibly unwanted dependencies.
Does adding a dependency to your proprietary logging framework sacrifice the reusability of the component?
Yes. But dependency injection will help in this case.
You can create an abstract logging base-class and create implementations for the logging-frameworks you want to use. Your components are just dependent on the abstract base-class. And you inject the implementations along with al their dependencies as needed.
Yes, Mendelt is right. We do exactly this in our products. Everything depends on the ILogger abstract interface, but it does not depend on anything else. Typically an executable or a high-level DLL will be the one to construct an actual implemented Logger interface and inject it.
If you are looking to build libraries which wont be recompiled, but want to provide a logging interface then perhaps a good way is to allow the user (of the library) to provide a callback.
On initialising logging with your library, they would need to specify the callback, and then the glue-code is up to them to make it play well with whatever they have.
If you can make the signature of the callback look like a standard function they might always have available to them, it provides them an easy default option if they dont actually have a logger.
Additionally the caller might have instanced components from the library multiple times, and for resource contention or threading issues, want to provide a different logger callback for each one.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I use the Boost Test framework for my C++ code but there are two problems with it that are probably common to all C++ test frameworks:
There is no way to create automatic test stubs (by extracting public functions from selected classes for example).
You cannot run a single test - you have to run the entire 'suite' of tests (unless you create lots of different test projects I guess).
Does anyone know of a better testing framework or am I forever to be jealous of the test tools available to Java/.NET developers?
I've just pushed my own framework, CATCH, out there. It's still under development but I believe it already surpasses most other frameworks.
Different people have different criteria but I've tried to cover most ground without too many trade-offs.
Take a look at my linked blog entry for a taster. My top five features are:
Header only
Auto registration of function and method based tests
Decomposes standard C++ expressions into LHS and RHS (so you don't need a whole family of assert macros).
Support for nested sections within a function based fixture
Name tests using natural language - function/ method names are generated
It doesn't do generation of stubs - but that's a fairly specialised area. I think Isolator++ is the first tool to truly pull that off. Note that Mocking/ stubbing frameworks are usually independent of unit testing frameworks. CATCH works particularly well with mock objects as test state is not passed around by context.
It also has Objective-C bindings.
[update]
Just happened back across this answer of mine from a few years ago. Thanks for all the great comments!
Obviously Catch has developed on a lot in that time. It now has support for BDD style testing (given/ when/ then), tags, now in a single header, and loads of internal improvements and refinements (e.g. richer command line, clear and expressive output etc). A more up-to-date blog post is here.
Take a look at the Google C++ Testing Framework.
It's used by Google for all of their in-house C++ projects, so it must be pretty good.
http://googletesting.blogspot.com/2008/07/announcing-new-google-c-testing.html
http://code.google.com/p/googletest
Boost.Test does allow to run test case by name. Or test suite. Or several of them.
Boost.Test does NOT insists on implementing main, though it does make it easy to do so.
Boost.Test is NOT necessary to use as a library. It has single header variant.
I just responded to a very similar question. I ended up using Noel Llopis' UnitTest++. I liked it more than boost::test because it didn't insist on implementing the main program of the test harness with a macro - it can plug into whatever executable you create. It does suffer from the same encumbrance of boost::test in that it requires a library to be linked in. I've used CxxTest, and it does come closer than anything else in C++-land to automatically generating tests (though it requires Perl to be part of your build system to do this). C++ just does not provide the reflection hooks that the .NET languages and Java do. The MsTest tools in Visual Studio Team System - Developer's Edition will auto-generate test stubs of unmanaged C++, but the methods have to be exported from a DLL to do this, so it does not work with static libraries. Other test frameworks in the .NET world may have this ability too, but I'm not familiar with any of those. So right now we use UnitTest++ for unmanaged C++ and I'm currently deciding between MsTest and NUnit for the managed libraries.
I'm a big fan of UnitTest++, it's very lightweight, but does the job. You can run single tests there easily.
Great question! A few years ago I looked around forever for something worth using and came up short. I was looking for something that was very lightweight and did not require me to link in some libraries... you know something I could get up and running in minutes.
However, I persisted and ended up running across cxxtest.
From the website:
Doesn't require RTTI
Doesn't require member template functions
Doesn't require exception handling
Doesn't require any external libraries (including memory management, file/console I/O, graphics libraries)
Is distributed entirely as a set of header files (and a python script).
Wow... super simple! Include a header file, derive from the Test class and you're off and running. We've been using this for the past four years and I've still yet to find anything that I'm more pleased with.
Try WinUnit. It sounds excellent, and is recommended by John Robbins.
I like the Boost unit test framework, principally because it is very lightweight.
I never heard of a unit-test framework that would generate stubs. I am generally quite unconvinced by code generation, if only because it gets obsolete very quickly. Maybe it becomes useful when you have a large number of classes?
A proponent of Test Driven Development would probably say that it is fundamental that you run the whole test suite every time, as to make sure that you have not introduced a regression. If running all the tests take too much time, maybe your tests are too big, or make too many calls to CPU intensive functions that should be mocked out? If it remains a problem, a thin wrapper around the boost unit-tests should allow you to pick your tests, and would probably be quicker than learn another framework and port all your tests.
http://groups.google.com/group/googletestframework, but it's pretty new
I'm using tut-framework
Aeryn is another framework worth looking at
Visual Studio has a built-in unit testing framework, this is a great link to setting up a test project for win32 console application:
http://codeketchup.blogspot.ie/2012/12/unit-test-for-unmanaged-c-in-visual.html
If you are working on a static DLL project it is much easier to set up as other have pointed out external tesing frameworks like GTest and Boost have extra features.
CppUnit was the original homage to JUnit.
Eclipse/JUnit is a solid package for java, and there are C++ extensions/equivalents for both. It can do what you're talking about. Of course, you'd have to change IDEs...
I too am a fan of UnitTest++.
The snag is that the source distribution contains almost 40 seperate files. This is absurd. Managing the source control and build tasks for a simple project is dominated by looking after all these unit testing files.
I have modified UnitTest++ so that it can be integrated with a project by adding one .h and .cpp file. This I have dubbed "cutest". Details are at http://ravenspoint.com/blog/index.php?entry=entry080704-063557
It does not automatically generate test stubs, as asked for in the original question. I cannot help thinking that such a feature would be more trouble than it is worth, generating vast amounts of useless code "testing" accessor functions.
I would imagine automatically stubbing out test functions would be more of a function (of scripts for the framework or) the development environment in question. Supposedly CodeGear's C++Builder applications will quickly generate test code for user functions.
Andrew Marlow's Fructose library's worth checking out... http://fructose.sourceforge.net/
I recall his documents containing a fairly detailed analysis and comparison of other offering at the time he wrote Fructose, but can't find a URL direct to that document.
I'm trying out Igloo, also a header only C++ test suite, even it's two included dependencies are header only.
So, it's pretty straightforward and simple. Besides the included example on github, there's examples and more details at the main site, igloo-testing.org. I'll update this later as I get more experience with it and other frameworks.