Writing tests to validate sketchup model

Hi,

I am developing an extension which allows a designer(user) to create pre defined models on one click. I am trying to write tests for this to verify the model created.

To test rightly I have to assert the differents entities created and there relationship on the canvas. But we are on a tight schedule and want to do this fastest way possible.

Is there a way I can store the model created somewhere? so that in my tests I just assert if the created model and saved model are same(to catch any regression).

I moved your topic into the right category.

However I don’t really understand what you want to achieve. Can you explain it in other words? Or with examples, screenshots?
Do you want to test geometric matching? Or that the model is saved? Or do you want to insert an existing model as a component with a click and check to see if you have already inserted it?..

I want to insert a model and verify that that is the model that was supposed to be inserted by comparing it with some saved model.
Below is how my test will look like. the saved_model part is very I need help. If there is some way I can save the model created on canvas then I can assert for regression.

class TC_add_product_1
# saved_model = this is the missing piece. How to save some model definition here.
def test_double_kitchen_cabinet
  Create_Product("product1") # This will create a product on canvas
  #model = get the model created from canvas
  # assert_equal(model, saved_model)
end
end

@dezmo did you get what I am trying to achieve?
Basically, I will have a saved model, I create a new model by calling an API and want to validate if the new model created is the same as the saved one.

I’m still not sure I understand. Especially the term “canvas” isn’t clear. I don’t think there is such a term in SU. There is a model were you can create a geometries, groups and components or insert a component.

You can load a file as component definition then insert instance to the entities collection.

Then you can compare it to the other component instance. If I understand right the your method will create a component instance:

created_instance = Create_Product("product1")

There are two methods come into my mind to compare this instances. (the created_instance vs. inserted “model” as component instance )

ComponentInstancel#equals-instance_method
ComponentInstance#show_differences-instance_method

As far as I know in Ruby, you can not compare it unless both are loaded to the model.


However there is a SketchUp C API could be that you are looking for.
The SketchUp C API is an interface for reading and writing data to and from SketchUp models. This API interacts directly with SketchUp files (.skp). It can create new ones as well as read or modify existing ones.

Unfortunately I have no experience with it at all :frowning:
Maybe someone (other forum member) can help!

If you have a geometries in a component:

ComponentDefinitionl#save_as-instance_method

Thanks @dezmo
The load and equals? method helped. I was able to catch regressions. I didn’t look into C API though.

1 Like

There isn’t any model comparison functionality in the API. You would have to write the comparison yourself.

I have written something like this myself for my own extensions; I will have a master model with the expected results. Then in my tests I will import the master as a component and use that as a reference when I compared my generated component. The actual comparison differ from extension to extension - depending on what features in the model is important for the extension. But typically I have a utility method that will loop over the faces in the master model, then try to look for a face in the generated model with matching vertex positions. Once I found one I will compare the properties of the face that I care about.