Tizen 2.1 base
[external/device-mapper.git] / test / api / percent.c
1 /*
2  * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
3  *
4  * This file is part of LVM2.
5  *
6  * This copyrighted material is made available to anyone wishing to use,
7  * modify, copy, or redistribute it subject to the terms and conditions
8  * of the GNU Lesser General Public License v.2.1.
9  *
10  * You should have received a copy of the GNU Lesser General Public License
11  * along with this program; if not, write to the Free Software Foundation,
12  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
13  */
14
15 #include "lvm2app.h"
16
17 #define assert(x) do { if (!(x)) goto bad; } while (0)
18
19 int main(int argc, char *argv[])
20 {
21         lvm_t handle;
22         vg_t vg = NULL;
23         lv_t lv;
24         struct lvm_property_value v;
25
26         handle = lvm_init(NULL);
27         assert(handle);
28
29         vg = lvm_vg_open(handle, argv[1], "r", 0);
30         assert(vg);
31
32         lv = lvm_lv_from_name(vg, "snap");
33         assert(lv);
34
35         v = lvm_lv_get_property(lv, "snap_percent");
36         assert(v.is_valid);
37         assert(v.value.integer == PERCENT_0);
38
39         lv = lvm_lv_from_name(vg, "mirr");
40         assert(lv);
41
42         v = lvm_lv_get_property(lv, "copy_percent");
43         assert(v.is_valid);
44         assert(v.value.integer == PERCENT_100);
45
46         lv = lvm_lv_from_name(vg, "snap2");
47         assert(lv);
48
49         v = lvm_lv_get_property(lv, "snap_percent");
50         assert(v.is_valid);
51         assert(v.value.integer == 50 * PERCENT_1);
52
53         lvm_vg_close(vg);
54         return 0;
55
56 bad:
57         if (handle && lvm_errno(handle))
58                 fprintf(stderr, "LVM Error: %s\n", lvm_errmsg(handle));
59         if (vg)
60                 lvm_vg_close(vg);
61         if (handle)
62                 lvm_quit(handle);
63         return 1;
64 }