Blender V5.3
wm_dragdrop_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
7/* #eFileSel_File_Types. */
8#include "DNA_space_types.h"
9
10#include "WM_api.hh"
11#include "WM_types.hh"
12
13namespace blender::tests {
14
16{
17 {
23 Vector<const char *> paths{"text_file.txt"};
24 wmDragPath *path_data = WM_drag_create_path_data(paths);
25 Vector<std::string> expected_file_paths{"text_file.txt"};
26
27 EXPECT_EQ(path_data->paths.size(), 1);
28 EXPECT_EQ(path_data->tooltip, "text_file.txt");
29 EXPECT_EQ(path_data->paths, expected_file_paths);
30
32 wmDrag drag;
33 drag.type = WM_DRAG_PATH;
34 drag.poin = path_data;
35 EXPECT_STREQ(WM_drag_get_single_path(&drag), "text_file.txt");
37 EXPECT_EQ(WM_drag_get_paths(&drag), expected_file_paths.as_span());
38 EXPECT_STREQ(WM_drag_get_single_path(&drag, FILE_TYPE_TEXT), "text_file.txt");
43 MEM_delete(path_data);
44 }
45 {
46 Vector<const char *> paths = {"blender.blend", "text_file.txt", "image.png"};
47 wmDragPath *path_data = WM_drag_create_path_data(paths);
48 Vector<std::string> expected_file_paths = {"blender.blend", "text_file.txt", "image.png"};
49
50 EXPECT_EQ(path_data->paths.size(), 3);
51 EXPECT_EQ(path_data->tooltip, "Dragging 3 files");
52 EXPECT_EQ(path_data->paths, expected_file_paths);
53
55 wmDrag drag;
56 drag.type = WM_DRAG_PATH;
57 drag.poin = path_data;
58 EXPECT_STREQ(WM_drag_get_single_path(&drag), "blender.blend");
60 EXPECT_EQ(WM_drag_get_paths(&drag), expected_file_paths.as_span());
61 EXPECT_STREQ(WM_drag_get_single_path(&drag, FILE_TYPE_BLENDER), "blender.blend");
62 EXPECT_STREQ(WM_drag_get_single_path(&drag, FILE_TYPE_IMAGE), "image.png");
63 EXPECT_STREQ(WM_drag_get_single_path(&drag, FILE_TYPE_TEXT), "text_file.txt");
64 EXPECT_STREQ(
66 "blender.blend");
68 "text_file.txt");
75 MEM_delete(path_data);
76 }
77 {
79 wmDrag drag;
80 drag.type = WM_DRAG_COLOR;
81 EXPECT_EQ(WM_drag_get_single_path(&drag), nullptr);
83 EXPECT_EQ(WM_drag_get_paths(&drag).size(), 0);
86 nullptr);
89 }
90}
91
92} // namespace blender::tests
Span< T > as_span() const
#define EXPECT_FALSE(result)
#define EXPECT_TRUE(result)
TEST(any_virtual, DefaultConstructor)
const char * WM_drag_get_single_path(const wmDrag *drag)
@ WM_DRAG_PATH
Definition WM_types.hh:1302
@ WM_DRAG_COLOR
Definition WM_types.hh:1312
bool WM_drag_has_path_file_type(const wmDrag *drag, int file_type)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
int WM_drag_get_path_file_type(const wmDrag *drag)
Span< std::string > WM_drag_get_paths(const wmDrag *drag)
wmDragPath * WM_drag_create_path_data(Span< const char * > paths)
Vector< std::string > paths
Definition WM_types.hh:1365
std::string tooltip
Definition WM_types.hh:1370
eWM_DragDataType type
Definition WM_types.hh:1424
int size() const
Definition vector.hh:130