How to set up a unit-tested C project in Eclipse - c

I'm sure this is documented somewhere but I'm struggling to find what I'm after. I am developing a project in C (and explicitly not C++), and having had good experiences developing Java projects with JUnit for TDD, I'd like to take a similar approach for this new project.
Can anyone provide a walkthrough for creating and running a simple C project, and running a couple of unit tests on them within Eclipse CDT? I have Eclipse CDT (Luna) and the unit-testing plugin as described in the frequently referenced blog. Most of the guidance appears to be for C++.
FWIW I'm running on Windows 7 and compiling with MinGW GCC.

Have you given google test a try? Its technically a c++ library, but has very little overhead to test your functions. A c++ test project would easily be able to consume the library generated from your c code, so should be pretty easy.
For example, this is what a test would look like
#include "gtest/gtest.h"
#include "MyProject/myFunc.h
TEST (myFuncTest, calculate) {
EXPECT_EQ (18.0, myFunc_calculate (324.0));
}
You can find more details at IBM Developerworks on YouTube etc.

After a lot of research, I tried most of the libraries for C and C++ testing and the one that was the right one for me was the Acutest.
I have created a public repository with an example that also uses Github Actions and a makefile in order to accomplish Continuous Integration (CI) by compiling the code and the tests and running them on every push automaticly.
Repository Link : CPP_Unit_Testing

Related

How to use Codenameone Source into Eclipse project?

I have an eclipse codenameone project. I would like to execute this project on Eclipse using my own codenameone modified sources (codenameone sources project is in netbeans). How could I do that ?
As it is mentioned in this video, we should linked the project in the build path but it works only if we have a netbean project.
Better solution is to edit Codenameone source in Eclipse (but sources in github has structure of a Netbeans project).
Thanks!
Right now debugging with the Codename One sources is only supported on NetBeans because that is the platforms we use for our coding. It's harder to work with other IDE's and might not be worth your effort.
Someone posted a while back in the discussion forum about running this in Eclipse but I couldn't find the reference.
Generally if you want to build the native sources and debug from there just work based on the logic we have and adapt it to Eclipse (or any other IDE). Running a Codename One project has 2 major dependencies:
Codename One project - that's a regular Java project you can work with
JavaSEPort another regular project, this is the implementation of the Codename One code and includes the simulator.
Make sure to add the source trees of both these projects to the compile but not packaging phases and set the Simulator class as your main class.
If you are successful in doing this it would be really nice if you write about it for the developer guide wiki next to the NetBeans build and explain how this is done for future developers.

How to compile Google Test using IAR compiler for ARM

I am trying to compile Google Test Framework using IAR compiler for ARM, but I face difficulties related to the lack of system libraries such as pthread.
Has anybody been able to compile Google Framework using IAR compiler for ARM?
I have tried for the past few days to get GoogleTest to work so that I can perform unit testing on our ARM microcontroller in IAR using the simulator and I've given up. Like you stated, I was running into issues like threading and libraries that aren't available in the IAR toolchain.
Instead, we've decided to move forward using a different framework that we've had success with so far called CppUTest. It also offers a mocking framework which we've been able to use. There's also the ability for CppUTest to use the GoogleMock mocking framework (which I haven't tried yet).
We've demonstrated that we're able to use CppUTest using GCC and IAR which allows us to use the GCOV capability provided by GCC but then switch over to the IAR compiler to verify the code will compile for our target.
A great reference that I found has been the book: Test Driven Development for Embedded C by James W. Grenning. It uses both CppUTest and Unity for their unit testing framework examples.
There may be plenty of other frameworks out there that will work as well we settled on CppUTest since there's examples in the book and it does everything we've needed so far.
I know it isn't the answer you were looking for, but I hope it helps!

How to program LEGO Mindstorms EV3 using C language?

First of all, I'm new for this and I need a little help!
I have a LEGO Mindstorms EV3 robot, I downloaded (LEGO Mindstorms EV3 Home Edition) to control the EV3. Unfortunately, I couldn't find the source code for the EV3 in the mentioned software. So, please if anybody could tell me the name of the software that enables you to program EV3! I would be most appreciated!
I also downloaded (Bricxcc) software but it was an old version. I couldn't find a newer version which contains EV3.
Can I use C language to program EV3 ? Or to add some features to the sensors?
Note: I ended with leJOS software to program the code with java it is much easier and there are a lot of resources for the EV3 brick in java. Wish you all the best!
You can find the EV3 source code here: https://github.com/mindboards/ev3sources
The generated documentation from this source code is available here and here.
Bricxcc has some experimental support for EV3 but it is not being actively developed (since Oct. 2013). You can find the latest test version here. Searching the web for "bricxcc ev3" will come up with some tutorials (for example, the one at http://www.robotnav.com looks good).
ROBOTC is a good alternative, although it is not free.
There is also ev3dev. There is a C library for ev3dev here or you can write your own.
The EV3 runs on Linux w/ glibc, so you only need to upload your C programs. For C++ you need to copy over the C++ standard library. Programming like that is a bit inconvenient, as you have to mess directly with the device files.
The c4ev3 bundle streamlines this. It's built around an Eclipse Plugin that includes a GCC Toolchain, an API and an integrated Uploader and File browser usable right out of Eclipse.
C and C++ Hello World template projects are included.
API and Uploader are also usable separately from Eclipse, so you can use it however you like.
Check it out :-)
Disclosure: I wrote part of the software.

check vs google test framework for c code

I want to setup a unit testing framework for a c project (c not c++). I have looked into
this list and checked out this stackoverflow question. I want a framework that I can easily setup for my project that only uses standard c libraries and is compiled and run on fedora 14 (64 bit version). It is not an embedded system like on the stackoverflow question. It looks like check and google test framework would work best. Do you guys know of any advantages/disadvantages of using one over the other or is their a better option out there? I have used JUnit and NUnit in the past for java and c# code. If it matters, I compile and run everything from the command line instead of using one of the IDEs.
... that only uses standard c libraries ...
Why is this requirement so important for the test framework if this is not an embedded system? I believe you can keep your production code c, while using any c++ framework.
If the requirement really is C only, I think it's pretty clear that you should go for Check.
If the requirement for C only is not for the test framework then I would go for Google Test, since, from what I have seen, it is offering more.
/Dan

Good IDE/compiler for simple C dll's

I'm trying to disassemble a C/C++ DLL, and have made some progress, but I would like to create my own C DLL with the same function the original exports, and compare disassemblies.
Visual Studio adds to much crap, and when I remove the crap and build my project, the expected DLL is missing.
I need a lightweight, preferably IDE, tool to edit and build very simple C libraries.
Take a look at Code::Blocks
I need a lightweight, preferably IDE, tool to edit and build very simple C libraries.
I have found that one of the best ways to do integrated C-only Win32 development is using the freely available Lcc Win32 Compiler which comes with a built-in IDE, including resource editor.
In fact, it is really very lightweight and can be run from a USB stick with some manual tweaking.
It's indeed a really small download of just 6 mb and you can even download an optional Win32 API help file which is really useful while doing development.
The compiler also comes with a C tutorial, as well as good user documentation detailing how to use the integrated Win32 resource editor "wedit", there's also an advanced manual about more complex development tasks.
Dev-C++ is a nice and fast IDE which works well with MingW.
But it's all been asked and answered before ...
MinGW adds its own crap. Install your VC express properly and save yourself a lifetime of trouble.
Btw, you don't need to use Visual Studio for its compiler or vice versa. The oddity of missing a build dll is probably because you are not looking at the right path.
If you are building C DLLs you really would benefit from its command line toolset and utilities, sdks, easy config etc. MS lock-in proprietary extensions are widely used (in context of you trying to emulate another dll), and last thing you need is chasing cross compiler issues..
GCC + any text editor such as VIM is a very light alternative.
For Windows Development, all you need is inside MinGW
Edit: If you are in dire need of an IDE you can also use the MinGW tools from Eclipse with the CDT plugin. Although it adds weight to the solution because of the installation of Eclipse, this is what I really use to build my small DLLs (JNI wrappers in my case).
You can setup your small and direct makefiles or let Eclipse do it automatically for you and concentrate only on the source files (*.h, *.c).
The best part of using this approach instead other IDE is that you do not need Eclipse to further build the DLL, since the underlying project files generated are standard ones directly usable by integrated dev inside MinGW (or any Unix distro) such as make, configure, automake, and so on.
I'll second the vote for Code::Blocks, it's what I use (despite having VS 2008 installed as well). It is very simple and lightweight but has basically all the features you'd expect out of an IDE. It comes with several predefined project templates for all kinds of C and C++ development, including templates for DLLs.
Download the version that includes MinGW and you get a complete lightweight IDE ready to start compiling. You can also easily configure it to use the Visual Studio compiler instead of gcc if you prefer.
try Open Watcom. A cross-platform product, well-supported by the community, lets you develop in DOS, Windows, OS/2 etc for a lot of platforms. Version 1.8 was released recently. Has a light-weight IDE indeed

Resources