How to mock 'Display' in googletest? - x11

In my program, using the API XOpenDisplay to get a Display. Then using the Display to get some XResource. Like that:
Display *dpy = XOpenDisplay(0);
char *resourceString = XResourceManagerString(dpy);
...
XCloseDisplay(dpy);
If you want to do googletest on this program,how should I mock Display or other X11 resource?

Related

How to download the image of an embeded message with disord.py

I am trying to be able to download the content of an embedded message.
This is what I am running so far
async def on_message(self, message):
embedFromMessage = message.embeds
print(embedFromMessage)
I would like it to output the url of the attached image and the description but is only outputting [discord.embeds.Embed object at 0x049A8990]
The discord.py API provides you a set of tools to allowing you to find what you're looking for.
Find the embed
As I see you're trying to catch an embedded message using the on_message event.
To do so we're going to use this :
#commands.Cog.listener()
async def on_message(self, message):
if(len(message.embeds) > 0):
This simple if statment will determine if the message is an embedded one or not.
If the message is an embed it will return a list of embeds.
Note that the image preview is considered as an embedded message.
Now let's catch the embed you want :
_embed = message.embeds[0] # this will return the first embed in message.embeds
Once we've stored the embed, we want to know if it contains an image :
if not _embed.image.url == discord.Embed.Empty:
image = _embed.image.url
By default, _embed.image will return an EmbedProxy which looks like that :
EmbedProxy(width=0, url='URL', proxy_url='PROXY_URL', height=0)
To access the value of url we have done _embed.image.url.
Now you have the image URL, you can download it using the aiohttp library for example.
The full code
Here is the code you can use to catch the image inside an embedded message as those that are created using the discord.Embed() class.
#commands.Cog.listener()
async def on_message(self, message):
if(len(message.embeds) > 0):
_embed = message.embeds[0]
if not _embed.image.url == discord.Embed.Empty:
image = _embed.image.url
channel = message.channel # get the channel where the embed has been sent
await channel.send(image) # send the image into the channel
Hope it helped !
Have a nice day !

Background process/task in genexus?

We're using Genexus EV3 to develop a project and we noticed that we can use it to easily alert users through SMS or emails about relevant information.
I'd like to know if it's possible to create some sort of background process in genexus that checks a database and so that we can send emails based on the information present in the database.
Thanks.
You can make a asynchronous call to a procedure object using the submit method, like:
// Some code...
prAnyProcedure.submit(&parm1, &parm2)
// Some code...
// Some code...
In this case, the main program flow will continue processing immediately.
But if you need to call a procedure from time to time without any user intervention, you should use a server-side tool like ant or the cron/crontab linux utility.
http://ant.apache.org/faq.html#what-is-ant
http://linux.die.net/man/8/cron
I made some like you need.
I made a procedure, make it MAIN and are launched with de squeduler task (it run every day at 9am). In a table I have the reminder and the mail addresses, the massage to sent etc. This is the main procedure
for each empresa
where EmpresaEstado=1
&Empresanombre=EmpresaNombre
&EmpresaEmail=EmpresaEmail
&EmpresaServidorSalida=EmpresaServidorSalida
&EmpresaServidorPassword=EmpresaServidorPassword
endfor
for each recordatorios
where RecordatoriosEstado=1
where RecordatoriosDiaEnvio=day(today())
&smtp.Host = 'smtp.gmail.com'
&smtp.Port = 25
&smtp.Sender.Address = TRIM(&EmpresaEmail)
&smtp.Sender.Name = TRIM(&empresanombre)
&smtp.Authentication = 1
&smtp.Secure=1
&smtp.UserName = TRIM(&empresaEmail)
&smtp.Password = trim(&EmpresaServidorPassword)
&recordatoriosasunto=RecordatoriosAsunto
&recordatoriostexto=RecordatoriosTexto
&mail.To.New('Mauricio','mlopez.informatica#gmail.com')
&smtp.ErrDisplay = 0
&smtp.Login()
for each
where RecordatoriosClienteEstado=1
&mail.BCC.new(RecordatoriosClienteMail1,trim(RecordatoriosClienteMail1))
if RecordatoriosClienteMail2<>''
&mail.BCC.new(RecordatoriosClienteMail2,trim(RecordatoriosClienteMail2))
endif
endfor
&mail.Subject = &recordatoriosasunto
&mail.Text = &recordatoriostexto
&smtp.Send(&mail)
&mail.Clear()
&smtp.Logout()
endfor

How to set message bus message type to JSON?

I am using the HelloTextGoogleCast sample's receiver.html. But I need to set the message bus's message type to JSON.
Here is part of it.
// create a CastMessageBus to handle messages for a custom namespace
window.messageBus =
window.castReceiverManager.getCastMessageBus(
'urn:x-cast:com.google.cast.sample.helloworld');
I tried this right after the above code. But it does not work:
window.messageBus = window.castReceiverManager.getCastMessageBus(cast.receiver.CastMessageBus.MessageType.JSON);
Use
window.messageBus =
window.castReceiverManager.getCastMessageBus(
'urn:x-cast:com.google.cast.sample.helloworld', cast.receiver.CastMessageBus.MessageType.JSON);

Why this Ruby + Qt code not working?

I have the following test code:
require 'Qt'
app = Qt::Application.new( ARGV )
wnd = Qt::Widget.new
layout = Qt::VBoxLayout.new( wnd )
splitter = Qt::Splitter.new( layout )
That fails in last line with strange error:
'initialize': unresolved constructor call Qt::Splitter (ArgumentError)
I have checked the Qt::Splitter API via rbqtapi, it has constructor that takes one Qt::Widget argument. What's wrong with that code?
layout is of type VBoxLayout, which is no base class of QWidget and thus cannot be used where an argument of type QWidget is expected. Guessing based on my experience with Qt in C++ and Python, I'd say you have to use:
splitter = Qt::Splitter.new(wnd)
layout.addWidget(splitter)

Sending An HTTP Request using Intersystems Cache

I have the following Business Process defined within a Production on an Intersystems Cache Installation
/// Makes a call to Merlin based on the message sent to it from the pre-processor
Class sgh.Process.MerlinProcessor Extends Ens.BusinessProcess [ ClassType = persistent, ProcedureBlock ]
{
Property WorkingDirectory As %String;
Property WebServer As %String;
Property CacheServer As %String;
Property Port As %String;
Property Location As %String;
Parameter SETTINGS = "WorkingDirectory,WebServer,Location,Port,CacheServer";
Method OnRequest(pRequest As sgh.Message.MerlinTransmissionRequest, Output pResponse As Ens.Response) As %Status
{
Set tSC=$$$OK
Do ##class(sgh.Utils.Debug).LogDebugMsg("Packaging an HTTP request for Saved form "_pRequest.DateTimeSaved)
Set dateTimeSaved = pRequest.DateTimeSaved
Set patientId = pRequest.PatientId
Set latestDateTimeSaved = pRequest.LatestDateTimeSaved
Set formName = pRequest.FormName
Set formId = pRequest.FormId
Set episodeNumber = pRequest.EpisodeNumber
Set sentElectronically = pRequest.SentElectronically
Set styleSheet = pRequest.PrintName
Do ##class(sgh.Utils.Debug).LogDebugMsg("Creating HTTP Request Class")
set HTTPReq = ##class(%Net.HttpRequest).%New()
Set HTTPReq.Server = ..WebServer
Set HTTPReq.Port = ..Port
do HTTPReq.InsertParam("DateTimeSaved",dateTimeSaved)
do HTTPReq.InsertParam("HospitalNumber",patientId)
do HTTPReq.InsertParam("Episode",episodeNumber)
do HTTPReq.InsertParam("Stylesheet",styleSheet)
do HTTPReq.InsertParam("Server",..CacheServer)
Set Status = HTTPReq.Post(..Location,0) Quit:$$$ISERR(tSC)
Do ##class(sgh.Utils.Debug).LogDebugMsg("Sent the following request: "_Status)
Quit tSC
}
}
The thing is when I check the debug value (which is defined as a global) all I get is the number '1' - I have no idea therefore if the request has succeeded or even what is wrong (if it has not)
What do I need to do to find out
A) What is the actual web call being made?
B) What the response is?
There is a really slick way to get the answer the two questions you've asked, regardless of where you're using the code. Check the documentation out on the %Net.HttpRequest object here: http://docs.intersystems.com/ens20102/csp/docbook/DocBook.UI.Page.cls?KEY=GNET_http and the class reference here: http://docs.intersystems.com/ens20102/csp/documatic/%25CSP.Documatic.cls?APP=1&LIBRARY=ENSLIB&CLASSNAME=%25Net.HttpRequest
The class reference for the Post method has a parameter called test, that will do what you're looking for. Here's the excerpt:
method Post(location As %String = "", test As %Integer = 0, reset As %Boolean = 1) as %Status
Issue the Http 'post' request, this is used to send data to the web server such as the results of a form, or upload a file. If this completes correctly the response to this request will be in the HttpResponse. The location is the url to request, e.g. '/test.html'. This can contain parameters which are assumed to be already URL escaped, e.g. '/test.html?PARAM=%25VALUE' sets PARAM to %VALUE. If test is 1 then instead of connecting to a remote machine it will just output what it would have send to the web server to the current device, if test is 2 then it will output the response to the current device after the Post. This can be used to check that it will send what you are expecting. This calls Reset automatically after reading the response, except in test=1 mode or if reset=0.
I recommend moving this code to a test routine to view the output properly in terminal. It would look something like this:
// To view the REQUEST you are sending
Set sc = request.Post("/someserver/servlet/webmethod",1)
// To view the RESPONSE you are receiving
Set sc = request.Post("/someserver/servlet/webmethod",2)
// You could also do something like this to parse your RESPONSE stream
Write request.HttpResponse.Data.Read()
I believe the answer you want to A) is in the Server and Location properties of your %Net.HttpRequest object (e.g., HTTPReq.Server and HTTPReq.Location).
For B), the response information should be in the %Net.HttpResponse object stored in the HttpResponse property (e.g. HTTPReq.HttpResponse) after your call is completed.
I hope this helps!
-Derek
(edited for formatting)
From that code sample it looks like you're using Ensemble, not straight-up Cache.
In that case you should be doing this HTTP call in a Business Operation that uses the HTTP Outbound Adapter, not in your Business Process.
See this link for more info on HTTP Adapters:
http://docs.intersystems.com/ens20102/csp/docbook/DocBook.UI.Page.cls?KEY=EHTP
You should also look into how to use the Ensemble Message Browser. That should help with your logging needs.

Resources