Hello @dale !
Thanks for taking the time, and just want to say that the Rhino.Inside C++ is quite something and enjoying very much running inside in C++. it’s amazing so thanks!
What I am trying to do is add a testing framework to my Rhino plugin.
It’s compiled in cmake and all the linking works both for the plugin compilation of .rhp and the test suite compilation. Here’s a quick diagram for context:
So, I am using Rhino.Inside C++ (amazing again) together with gtest to run integration and unit testing on the commands. This is because I want to run my suite nicely from my console but also potentially on a CI server.
So unit testing is easy, and for integration/smoke test (aka running the command in Rhino), I found the following way:
Given my command like this:
CRhinoCommand::result CCommandcmake4rhino::RunCommand(const CRhinoCommandContext& context)
{
...
// Testing text input
CRhinoGetString gs;
gs.SetCommandPrompt(L"Testing input");
gs.GetString();
if (gs.CommandResult() != CRhinoCommand::success)
return gs.CommandResult();
ON_wString block_name = gs.String();
block_name.TrimLeftAndRight();
if (block_name.IsEmpty())
return CRhinoCommand::cancel;
// add a simple curve circle to test geometries
ON_3dPoint center(0, 0, 0);
double radius = 10.0;
ON_Circle circle( center, radius );
ON_ArcCurve arc_curve( circle );
CRhinoCurveObject* curve_object = context.m_doc.AddCurveObject( arc_curve );
context.m_doc.Redraw();
...
}
And my test is the following: it seemed to me using macros was the easiest way to test the integration of the commands..
#include <gtest/gtest.h>
#include "pch.h"
#include "RhinoCore.h"
TEST(TEST_INTEGRATION_CommandsSuite, MyIntegrationTest) {
CRhinoCreateDocumentOptions options;
options.SetCreateHeadless(true);
int doc_runtime_serial_number = CRhinoDoc::CreateDocument(nullptr, &options);
CRhinoDoc* pDoc = CRhinoDoc::FromRuntimeSerialNumber(doc_runtime_serial_number);
const wchar_t* cmdName = L"!_cmake4rhino \"test\" _Enter";
bool resCmd = pDoc->ExecuteCommand(cmdName);
ASSERT_TRUE(resCmd);
}
And the test is working locally:
So I haven’t tested UI but in this scenario I would always test it with the - “no dialog flag”.
Nevertheless, command line interaction seems to work as shown in the the example above.
So here are my doubts @dale
- is there a better way to build a test suite for a
.rhp plugin in Rhino?
- what is running behind the curtains of
SetCreateHeadless() and what are their limits?
This is such an interesting topic and having a feedback on this would be great! Thanks in advance 