/ test / common_gui.cpp
common_gui.cpp
 1  #include "common_gui.h"
 2  
 3  #include <gui/mainwindow.h>
 4  
 5  #include "common.h"
 6  
 7  namespace NeovimQt {
 8  
 9  static const QStringList cs_argsNone{ "-u", "NONE" }; // clazy:exclude=non-pod-global-static
10  
11  static void DisableLocalGInitVim() noexcept
12  {
13  	// Check environment variable GVIMINIT, skip if already set.
14  	const QByteArray ginitVar{ "GVIMINIT" };
15  	if (!qEnvironmentVariableIsEmpty(ginitVar)) {
16  		return;
17  	}
18  
19  	// Do not pull in the local machine's ginit.vim file for tests.
20  	qputenv(ginitVar, ";");
21  }
22  
23  template<class T> static void ValidateNeovimConnection(T* obj) noexcept
24  {
25  	QSignalSpy onAttached{ obj, &T::neovimAttachmentChanged };
26  
27  	Q_ASSERT(onAttached.isValid());
28  
29  	const bool signalEmitted{ onAttached.wait() };
30  	Q_ASSERT(signalEmitted);
31  
32  	const qsizetype signalCount{ onAttached.count() };
33  	Q_ASSERT(signalCount == 1);
34  
35  	Q_ASSERT(obj->isNeovimAttached());
36  }
37  
38  QSharedPointer<Shell> CreateShellWidget() noexcept
39  {
40  	DisableLocalGInitVim();
41  	NeovimConnector* c{ NeovimConnector::spawn(cs_argsNone) };
42  	Shell* s{ new Shell{ c } };
43  
44  	s->show();
45  
46  	ValidateNeovimConnection(s);
47  
48  	return QSharedPointer<Shell>(s);
49  }
50  
51  QSharedPointer<MainWindow> CreateMainWindow() noexcept
52  {
53  	NeovimConnector* c{ NeovimConnector::spawn(cs_argsNone) };
54  	MainWindow* w{ new MainWindow{ c } };
55  
56  	w->show();
57  
58  	ValidateNeovimConnection(w);
59  
60  	return QSharedPointer<MainWindow>(w);
61  }
62  
63  QSharedPointer<MainWindow> CreateMainWindowWithRuntime() noexcept
64  {
65  	static const QStringList cs_argsNoneRuntime{
66  		"-u", "NONE", "--cmd", "set rtp+=" + GetRuntimeAbsolutePath()
67  	};
68  
69  	DisableLocalGInitVim();
70  	NeovimConnector* c{ NeovimConnector::spawn(cs_argsNoneRuntime) };
71  	MainWindow* w{ new MainWindow{ c } };
72  
73  	w->show();
74  
75  	ValidateNeovimConnection(w);
76  
77  	return QSharedPointer<MainWindow>(w);
78  }
79  
80  } // namespace NeovimQt