forked from dacap/clip
-
Notifications
You must be signed in to change notification settings - Fork 6
/
user_format_tests.cpp
78 lines (68 loc) · 1.9 KB
/
user_format_tests.cpp
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
77
78
// Clip Library
// Copyright (C) 2018 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#include "test.h"
#include "clip.h"
#include <cstring>
#include <string>
#include <vector>
using namespace clip;
int main(int argc, char** argv)
{
format intF = register_format("com.github.clip.int");
format doubleF = register_format("com.github.clip.double");
EXPECT_TRUE(intF != empty_format());
EXPECT_TRUE(doubleF != empty_format());
// Clear clipboard content
{
clear();
EXPECT_FALSE(has(text_format()));
EXPECT_FALSE(has(intF));
EXPECT_FALSE(has(doubleF));
}
// Set int and double formats
{
lock l;
int intV = 32;
double doubleV = 32.48;
EXPECT_TRUE(l.set_data(intF, (const char*)&intV, sizeof(int)));
EXPECT_TRUE(l.set_data(doubleF, (const char*)&doubleV, sizeof(double)));
}
EXPECT_FALSE(has(text_format()));
EXPECT_TRUE(has(intF));
EXPECT_TRUE(has(doubleF));
// Get int and double formats
{
lock l;
int intV = 0;
double doubleV = 0.0;
EXPECT_TRUE(l.get_data(intF, (char*)&intV, sizeof(int)));
EXPECT_TRUE(l.get_data(doubleF, (char*)&doubleV, sizeof(double)));
EXPECT_EQ(32, intV);
EXPECT_EQ(32.48, doubleV);
}
// Add text to clipboard
{
lock l;
EXPECT_TRUE(l.set_data(text_format(), (const char*)"thirty-two", 10));
}
EXPECT_TRUE(has(text_format()));
EXPECT_TRUE(has(intF));
EXPECT_TRUE(has(doubleF));
// Get all formats
{
lock l;
int intV = 0;
double doubleV = 0.0;
char buf[11];
EXPECT_EQ(11, l.get_data_length(text_format()));
EXPECT_TRUE(l.get_data(text_format(), (char*)buf, 11));
EXPECT_TRUE(l.get_data(intF, (char*)&intV, sizeof(int)));
EXPECT_TRUE(l.get_data(doubleF, (char*)&doubleV, sizeof(double)));
EXPECT_EQ("thirty-two", std::string(buf));
EXPECT_EQ(32, intV);
EXPECT_EQ(32.48, doubleV);
}
}