File: TestF3DAssimpImportError.cxx

package info (click to toggle)
f3d 3.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,668 kB
  • sloc: cpp: 99,109; python: 811; sh: 342; xml: 238; java: 101; javascript: 95; makefile: 25
file content (76 lines) | stat: -rw-r--r-- 1,875 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <vtkNew.h>
#include <vtkTestUtilities.h>

#include "vtkCommand.h"
#include "vtkF3DAssimpImporter.h"

#include <iostream>
#include <vector>

class ErrorEventCallback : public vtkCommand
{
public:
  static ErrorEventCallback* New()
  {
    return new ErrorEventCallback;
  }

  void Execute(vtkObject* caller, unsigned long vtkNotUsed(evId), void* data) override
  {
    auto importer = reinterpret_cast<vtkF3DAssimpImporter*>(caller);
    char* message = static_cast<char*>(data);
    if (importer && message)
    {
      this->Messages.emplace_back(message);
    }
  }

  const std::vector<std::string>& GetRecordedErrorMessages() const
  {
    return this->Messages;
  }

private:
  std::vector<std::string> Messages;
};

int TestF3DAssimpImportError(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
{
  vtkNew<vtkF3DAssimpImporter> importer;

  vtkNew<ErrorEventCallback> errorEventCallback;
  importer->AddObserver(vtkCommand::ErrorEvent, errorEventCallback);

  importer->SetFileName("dummy.dae");
  importer->Update();

  auto errorMessages = errorEventCallback->GetRecordedErrorMessages();
  if (errorMessages.empty())
  {
    std::cerr << "No error triggered." << std::endl;
    return EXIT_FAILURE;
  }

  auto lastMessage = errorMessages.back();
  if (lastMessage.find("Assimp error") == std::string::npos)
  {
    std::cerr << "No Assimp error triggered!" << std::endl;
    return EXIT_FAILURE;
  }

  if (importer->GetNumberOfAnimations() != 0)
  {
    std::cerr << "Importer has " << importer->GetNumberOfAnimations()
              << " animations, expected 0 animation." << std::endl;
    return EXIT_FAILURE;
  }

  if (!importer->UpdateAtTimeValue(0))
  {
    std::cerr << "Importer did not return true with no animation enabled "
              << "when calling UpdateAtTimeValue()" << std::endl;
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}