Example #1
0
void checkLower(JsonVariant a, T b) {
  REQUIRE(a < b);
  REQUIRE(b > a);
  REQUIRE(a != b);
  REQUIRE(b != a);

  REQUIRE_FALSE(a > b);
  REQUIRE_FALSE(b < a);
  REQUIRE_FALSE(a == b);
  REQUIRE_FALSE(b == a);
}
Example #2
0
        void conversation_service::fire_contact_added(
                const std::string& conversation_id, 
                const std::string& contact_id)
        {
            REQUIRE_FALSE(conversation_id.empty());
            REQUIRE_FALSE(contact_id.empty());

            event::contact_added e;
            e.conversation_id = conversation_id;
            e.contact_id = contact_id;
            send_event(e.to_message());
        }
Example #3
0
TEST(optional, can_set_value) {
    optional<int> opt;
    opt = 4;
    REQUIRE(opt);
    REQUIRE(opt.has_value());
    REQUIRE(opt.value() == 4);
    REQUIRE(opt == 4);
    REQUIRE_FALSE(opt == 5);
    REQUIRE(opt != -4);
    REQUIRE_FALSE(opt != 4);
    REQUIRE(opt < 5);
    REQUIRE_FALSE(opt < 2);
    REQUIRE(opt <= 4);
    REQUIRE_FALSE(opt <= 2);
    REQUIRE(opt > 2);
    REQUIRE_FALSE(opt > 5);
    REQUIRE(opt >= 4);
    REQUIRE_FALSE(opt >= 9);
    REQUIRE(opt == optional<int>(4));
    REQUIRE(optional<int>(4) == opt);
    REQUIRE(opt != optional<int>(10));
    REQUIRE(optional<int>(10) != opt);
    REQUIRE_FALSE(opt == optional<int>());
    REQUIRE_FALSE(optional<int>() == opt);
    REQUIRE(opt != optional<int>());
    REQUIRE(optional<int>() != opt);
}
Example #4
0
        void conversation_service::fire_not_part_of_clique(
                const std::string& conversation_id, 
                const std::string& contact_id,
                const contact_id_set& contacts)
        {
            REQUIRE_FALSE(conversation_id.empty());
            REQUIRE_FALSE(contact_id.empty());
            REQUIRE_FALSE(contacts.empty());

            event::not_part_of_clique e;
            e.conversation_id = conversation_id;
            e.contact_id = contact_id;
            e.dont_know = contacts;
            send_event(e.to_message());
        }
Example #5
0
TEST(optional, can_have_no_value) {
    test_no_value<int>();
    test_no_value<char>();
    test_no_value<float>();
    test_no_value<double>();
    optional<int> opt;
    for (signed char i = -127; i < 127; i++) {
        REQUIRE_FALSE(opt == (signed char)3);
        REQUIRE(opt != (signed char)3);
        REQUIRE_FALSE(opt > i);
        REQUIRE_FALSE(opt >= i);
        REQUIRE_FALSE(opt < i);
        REQUIRE_FALSE(opt <= i);
    }
}
Example #6
0
                virtual t front()
                {
                    std::lock_guard<std::mutex> lock(_m);
                    REQUIRE_FALSE(_q.empty());

                    return _q.front();
                }
Example #7
0
            void script_app::contact_quit(const std::string& id)
            {
                REQUIRE_FALSE(id.empty());
                INVARIANT(_back);

                _back->contact_quit(id);
            }
Example #8
0
            void script_app::setup_decorations()
            {
                INVARIANT(_app);
                INVARIANT(_app_service);
                REQUIRE_FALSE(_clone);

                set_title(_app->name().c_str());

                _clone = new QPushButton;
                make_install(*_clone);

                //color the install icon depending on whether the app is already installed
                bool exists = _app_service->available_apps().count(_app->id());
                if(exists) 
                {
                    _clone->setToolTip(tr("update app"));
                    _clone->setStyleSheet("border: 0px; color: 'black';");
                }
                else
                {
                    _clone->setToolTip(tr("install app"));
                }

                connect(_clone, SIGNAL(clicked()), this, SLOT(clone_app()));

                layout()->addWidget(_clone, 0,2);

                ENSURE(_clone);
            }
Example #9
0
            script_app::script_app(
                    const std::string& from_id, 
                    const std::string& id, 
                    app_ptr app, app_service_ptr as, 
                    s::conversation_service_ptr conversation_s,
                    s::conversation_ptr conversation) :
                generic_app{},
                _from_id{from_id},
                _id{id},
                _conversation_service{conversation_s},
                _conversation{conversation},
                _app{app},
                _app_service{as}
            {
                REQUIRE(conversation_s);
                REQUIRE(conversation);
                REQUIRE(app);
                REQUIRE(as);
                REQUIRE_FALSE(id.empty());

                init();

                INVARIANT(_api);
                INVARIANT(_conversation_service);
                INVARIANT(_conversation);
                INVARIANT(_app);
                INVARIANT(_app_service);
                INVARIANT_FALSE(_id.empty());
            }
Example #10
0
            u::bytes microphone::encode(const u::bytes& b)
            {
                REQUIRE(_opus);
                REQUIRE_FALSE(b.empty());

                return _opus->encode({b}).data;
            }
Example #11
0
                    /**
                     * returns -1 if o is greater
                     * returns 0 may be identical, or may not be
                     * returns 1 if o is less
                     */
                    int compare(const tracked_vclock& o) const
                    {
                        REQUIRE_FALSE(o._c.empty());
                        INVARIANT(_c.has(_i));

                        return _c.compare(o._c);
                    }
Example #12
0
        void app_area::add(a::generic_app* t, a::app_ptr app, const std::string& id)
        {
            REQUIRE(t);
            REQUIRE(_conversation);
            REQUIRE(t->mail());
            REQUIRE_FALSE(t->mail()->address().empty());
            
            if(auto post = _conversation->parent_post().lock())
            {
                //add to conversation
                add(t);
                s::app_metadatum meta{ t->type(), id, t->mail()->address() };
                _conversation->add_app(meta);

                //add widget mailbox to master
                post->add(t->mail());

                //send new app message to contacts in conversation
                u::bytes encoded_app;
                if(app)
                {
                    m::message app_message = *app;
                    encoded_app = u::encode(app_message);
                }

                app_pair p{app, t};
                _apps[t->mail()->address()] = p;

                ms::new_app n{t->id(), t->type(), encoded_app}; 
                _conversation->send(n);
            }
        }
Example #13
0
        void conversation_service::fire_conversation_synced_event(const std::string& id)
        {
            REQUIRE_FALSE(id.empty());

            event::conversation_synced e;
            e.conversation_id = id;
            send_event(e.to_message());
        }
Example #14
0
bool delete_file(const std::string& file)
{
    REQUIRE_FALSE(file.empty());
    if(!bf::exists(file)) return false;

    bf::remove(file);
    return !bf::exists(file);
}
Example #15
0
bool create_directory(const std::string& dir)
{
    REQUIRE_FALSE(dir.empty());

    if(bf::exists(dir)) return true;

    bf::create_directories(dir);
    return bf::exists(dir);
}
Example #16
0
bool delete_directory(const std::string& dir)
{
    REQUIRE_FALSE(dir.empty());

    if(!bf::exists(dir)) return false;

    bf::remove_all(dir);
    return !bf::exists(dir);
}
Example #17
0
                    /**
                     * Merge tracked clock. 
                     */
                    tracked_vclock& operator += (const tracked_vclock& o) 
                    {
                        REQUIRE_FALSE(o._c.empty());

                        //merge clock
                        _c += o._c;

                        INVARIANT(_c.has(_i));
                        return *this;
                    }
Example #18
0
        public_key::public_key(const std::string& key) : 
            _ks(key)
        {
            REQUIRE_FALSE(key.empty());

            set(key);

            INVARIANT(_k);
            INVARIANT_FALSE(_ks.empty());
        }
Example #19
0
                virtual t pop()
                {
                    std::lock_guard<std::mutex> lock(_m);
                    REQUIRE_FALSE(_q.empty());

                    t v = std::move(_q.front());
                    _q.pop_front();

                    return v;
                }
Example #20
0
            //decimate sound to SAMPLE_RATE, using averaging
            void decimate(const u::bytes& s, u::bytes& d, size_t channels, size_t skip) 
            {
                REQUIRE_FALSE(s.empty());
                REQUIRE_EQUAL(s.size() % 2, 0);

                //get sizes
                auto dz = (s.size() / skip);
                auto nz = d.size() + dz;

                //add padding
                if(nz % 2 == 1) nz += 1;
                CHECK_EQUAL(nz % 2, 0);

                //resize dest
                const auto odz = d.size();
                d.resize(nz);

                //cast to short arrays
                auto ss = reinterpret_cast<const short*>(s.data());
                const auto sz = s.size() / 2;
                auto sd = reinterpret_cast<short*>(d.data());
                const auto sdz = nz / 2;

                int accum = 0;
                size_t c = 1;
                size_t si = 0;
                auto di = odz / 2;

                for(;si < sz; si+=channels)
                {
                    accum += static_cast<int>(ss[si]);
                    if(c == skip)
                    {
                        accum /= c;
                        sd[di] = accum;
                        di++;

                        accum = 0;
                        c = 1;
                        continue;
                    }
                    c++;
                }

                //repeat last value if we have padding
                si = sz-1;
                while(di < sdz)
                {
                    sd[di] = ss[si];
                    di++;
                }

                CHECK_EQUAL(di, sdz);
            }
Example #21
0
        void public_key::set(const std::string& key) 
        {
            REQUIRE_FALSE(key.empty());
            u::mutex_scoped_lock l(BOTAN_MUTEX);

            b::DataSource_Memory ds{reinterpret_cast<const b::byte*>(&_ks[0]), _ks.size()};
            _k.reset(b::X509::load_key(ds));

            INVARIANT(_k);
            INVARIANT_FALSE(_ks.empty());
        }
Example #22
0
void checkIsString(JsonVariant var) {
  REQUIRE(var.is<const char*>());

  REQUIRE_FALSE(var.is<bool>());
  REQUIRE_FALSE(var.is<int>());
  REQUIRE_FALSE(var.is<double>());
  REQUIRE_FALSE(var.is<float>());
  REQUIRE_FALSE(var.is<long>());
  REQUIRE_FALSE(var.is<JsonArray>());
  REQUIRE_FALSE(var.is<JsonObject>());
}
Example #23
0
            void chat_app::contact_quit(const std::string& id)
            {
                REQUIRE_FALSE(id.empty());
                INVARIANT(_messages);
                INVARIANT(_conversation);

                auto c = _conversation->user_service()->by_id(id);
                if(!c) return;

                std::stringstream s;
                s << c->name() << " quit";
                add_text(make_message_str("red", "notice", s.str()));
            }
Example #24
0
            void chat_app::contact_joined(const std::string& id)
            {
                REQUIRE_FALSE(id.empty());
                INVARIANT(_messages);
                INVARIANT(_conversation);

                LOG << id << "joined chat" << std::endl;
                auto c = _conversation->contacts().by_id(id);
                if(!c) return;

                std::stringstream s;
                s << c->name() << " joined";
                add_text(make_message_str("red", "notice", s.str()));
            }
Example #25
0
        service::service(
                const std::string& address, 
                message::mailbox_ptr event) :
            _address{address},
            _done{false},
            _event{event}
        {
            REQUIRE_FALSE(address.empty());

            _mail = std::make_shared<m::mailbox>(_address);

            ENSURE(_mail);
            ENSURE(_thread == nullptr);
        }
Example #26
0
void send_response(
        n::connection_manager& con, 
        sc::encrypted_channels& sec, 
        const ms::greet_find_response& r, 
        const user_info& u)
{
    REQUIRE_FALSE(u.tcp_ep.protocol.empty());
    m::message m = r;

    auto address = n::make_address_str(u.tcp_ep); 
    m.meta.to = {address, u.response_service_address};

    //encrypt using public key
    auto data = u::encode(m);
    data = u::compress(data);
    data = sec.encrypt(address, data);
    con.send(address, data);
}
Example #27
0
void checkEquals(JsonVariant a, T b) {
  REQUIRE(b == a);
  REQUIRE(a == b);
  REQUIRE(b <= a);
  REQUIRE(a <= b);
  REQUIRE(b >= a);
  REQUIRE(a >= b);

  REQUIRE_FALSE(b != a);
  REQUIRE_FALSE(a != b);
  REQUIRE_FALSE(b > a);
  REQUIRE_FALSE(a > b);
  REQUIRE_FALSE(b < a);
  REQUIRE_FALSE(a < b);
}
Example #28
0
        void conversation_service::ask_about(
                        const std::string& id,
                        conversation_ptr s)
        {
            REQUIRE_FALSE(id.empty());
            REQUIRE(s);
            INVARIANT(_sender);

            s->asked_about(id);

            ask_contact_req_msg r;
            r.id = id;
            r.conversation_id = s->id();
            auto m = r.to_message();

            for(auto c : s->contacts().list())
            {
                CHECK(c);
                _sender->send(c->id(), m);
            }
        }
Example #29
0
            bin_data opus_encoder::encode(const bin_data& b)
            {
                REQUIRE(_opus);
                REQUIRE_FALSE(b.data.empty());
                if(b.data.size() != MIN_BUF_SIZE) return {};

                u::bytes r;
                r.resize(MIN_BUF_SIZE);
                auto size = opus_encode(_opus, 
                        reinterpret_cast<const opus_int16*>(b.data.data()),
                        FRAMES,
                        reinterpret_cast<unsigned char*>(r.data()),
                        r.size());

                if(size < 0) 
                {
                    LOG << "opus encode error: "; log_opus_error(size);
                    return {};
                }
                r.resize(size);
                return {r};
            }
Example #30
0
 virtual void pop_front()
 {
     std::lock_guard<std::mutex> lock(_m);
     REQUIRE_FALSE(_q.empty());
     _q.pop_front();
 }